import {ElMessage, ElMessageBox} from 'element-plus'
import html2canvas from "html2canvas";
import {nextTick, onMounted, ref} from "vue";
import {onBeforeRouteLeave} from "vue-router";
import {http} from "api/axios.js";
import emitter from "@/event/EventBus.js";
import Calculator from "./Calculator.js";
import {QuestionFilled} from "@element-plus/icons-vue";

export default {
    components: {QuestionFilled},
    setup() {
        const user = JSON.parse(localStorage.getItem("user"))
        //基础属性
        const basics = ref({
            coreAttribute: 1596,
            criticalStrike: 252,
            constitution: 639,
            physicalDefense: 878,
            magicDefense: 878,
        })
        //法宝属性
        const aMagicWeapon = {level: 40, coreAttribute: 938, HP: 3745}
        const aMagicWeaponList = ref([])
        const maxValue = ref(0)
        const minValue = ref(0)
        //境界
        const currentRealm = ref({constitution: 346.6, coreAttribute: 868.36, cultivationLevel: "筑基二", id: 3, spiritualRootLimit: 6970})
        const realmList = ref([])
        const className = [{value: '青云'}, {value: '焚香'}, {value: '鬼王'}, {value: '合欢'}, {value: '灵汐'}]
        const currentClassName = ref(localStorage.getItem("currentClassName") ? "青云" : localStorage.getItem("currentClassName"))
        const currentClassSchool = ref("")
        const classSchool = ref(["", ""])

        const allEquipment = ref([])
        const classEquipment = ref({Weapon: [], Head: [], UpperBody: [], Hand: [], Waist: [], Foot: [], Charm1: [], Charm2: [], Seal: [], Token: []})
        //当前装备列表
        const currentEquipment = ref([])
        const charm1 = ref({
            id: 0, equipmentName: "", partType: 0, equipageClass: 0, coreAttribute: 0, constitution: 0,
            physicalDefense: 0, magicDefense: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0,
            accuracy: 0, equipmentSource: "无", qualityLevel: 0, isLoongSpiritEnhanced: false
        })
        const charm2 = ref({
            id: 0, equipmentName: "", partType: 0, equipageClass: 0, coreAttribute: 0, constitution: 0,
            physicalDefense: 0, magicDefense: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0,
            accuracy: 0, equipmentSource: "无", qualityLevel: 0, isLoongSpiritEnhanced: false
        })
        //装备总属性
        const totalAttribute = ref({constitution: 0, coreAttribute: 0, physicalDefense: 0, magicDefense: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, accuracy: 0})
        //当前选择的套装
        const currentSuitLevel = ref()
        const suitNumber315 = ref(0)
        const suitSize1 = ref(0)
        const suitSize2 = ref(0)
        const suitAttribute1 = ref([])
        const suitAttribute2 = ref([])
        const suitLevel = ref([{name: "否", level: 0}, {name: "桑约·玄", level: 315}, {name: "桑约·极", level: 325}])
        //当前日月星值
        const currentSunMoonStarValue = ref({'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0})
        //当前护符日月星效果贴膜
        const currentEquipmentSunMoonStar = ref([])
        //日月星效果选择列表
        const sunMoonStar = [
            {name: "无 ", type: -1, effect: ""},
            {name: "旭日凌空", type: 0, effect: "每带有2点耀日，造成的伤害和治疗增加0.55%"},
            {name: "孤月葬魂", type: 1, effect: "每带有2点残月，造成的属性伤害增加0.6%"},
            {name: "星陨离歌", type: 2, effect: "每带有2点流星，受到伤害降低0.5%，造成治疗增加0.55%"},
            {name: "永夜哀歌", type: 3, effect: "当同时带有曜日、残月和流星属性时，造成的会心伤害和会心治疗增加9%"},
            {name: "混沌归墟", type: 4, effect: "当带有的耀日、残月和流星属性中最高值大于17时，增加480点核心属性"},
            {name: "太虚流光", type: 5, effect: "每带有200点最高的额外属性（会心、专精、调息和破甲），增加耀日、残月和流星中最高值2.4倍的核心属性"}
        ]
        const randomAttribute1 = ref()
        const randomAttribute2 = ref()
        const randomAttribute1List = [
            {name: "会心", type: 0, value: 254},
            {name: "调息", type: 1, value: 254},
            {name: "专精", type: 2, value: 254},
            {name: "破甲", type: 3, value: 254},
            {name: "命中", type: 4, value: 254}
        ]
        const randomAttribute2List = [
            {name: "会心", type: 0, value: 28},
            {name: "调息", type: 1, value: 28},
            {name: "专精", type: 2, value: 28},
            {name: "破甲", type: 3, value: 28},
            {name: "命中", type: 4, value: 28}
        ]
        const sunMoonStarResult = ref([])
        //武器套装
        const weaponSuit = ref(0)
        //防具套装
        const armorSuit = ref(0)
        //特殊效果列表
        const specialAttributeList = ref([])
        const currentInlay = ref({
            //头盔灌注
            head: [],
            //上衣灌注
            clothing: [],
            //手部灌注
            hand: [],
            //腰部关注
            waist: []
        })
        const inlayList = ref({
            //头盔灌注
            head: [],
            //上衣灌注
            clothing: [],
            //手部灌注
            hand: [],
            //腰部关注
            waist: []
        })
        //所有灌注的总属性
        const totalInlayAttribute = ref({coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, accuracy: 0, hp: 0})
        //当前神兵强化等级
        const currentWeaponEnhancedLevel = ref(0)
        const weaponEnhancedSelectList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        //当前防具强化等级
        const currentArmorEnhancedLevel = ref({"0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0})
        //当前首饰强化等级
        const currentJewelryEnhancedLevel = ref({"6": 0, "7": 0, "8": 0, "9": 0})
        //防具和首饰的强化等级
        const enhancedLevel = ref([])
        //防具和首饰的强化结果
        const enhancedAttribute = ref({"1": {}, "2": {}, "3": {}, "4": {}, "5": {}, "6": {}, "7": {}, "8": {}, "9": {}})
        //防具和首饰的强化属性总和
        const totalEnhancedAttribute = ref({coreAttribute: 0, constitution: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, accuracy: 0})
        //天书-会心
        const currentSkillTreeCriticalStrike = ref(0)
        const skillTreeCriticalStrike = ref([])
        //天书-调息
        const currentSkillTreeRecovery = ref(0)
        const skillTreeRecovery = ref([])
        //天书-专精
        const currentSkillTreeExpertise = ref(0)
        const skillTreeExpertise = ref([])
        //天书-防御
        const currentSkillTreeDefense = ref(0)
        const skillTreeDefense = ref([])
        //天书-气血
        const currentSkillTreeHP = ref(0)
        const skillTreeHp = ref([])

        const isShowCriticalStrike = ref(false)
        const isShowRecovery = ref(false)
        const isShowExpertise = ref(false)
        const isShowDefense = ref(false)
        const isShowHp = ref(false)
        //当前法宝
        const currentAMagicWeapon = ref({id: 0, name: "无", criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, accuracy: 0})
        const xingPoLevel = [
            {"level": "0", "attribute": 0, "coreAttribute": 0, "HP": 0},
            {"level": 295, "attribute": 35, "coreAttribute": 159, "HP": 628},
            {"level": 315, "attribute": 42, "coreAttribute": 193, "HP": 753},
            {"level": 335, "attribute": 51, "coreAttribute": 230, "HP": 900}]
        //当前星魄选择
        const currentXingPo = ref({"青龙": xingPoLevel[2], "白虎": xingPoLevel[2], "玄武": xingPoLevel[2], "朱雀": xingPoLevel[2]})
        //星魄总属性
        const totalXingPoAttribute = ref({coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, hp: 0})

        const danYaoList = [
            {name: "无", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, color: "#333333"},
            {name: "紫霞明神丸[80专精]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 80, armorPenetration: 0, color: "darkorchid"},
            {name: "九霄仙心丸[80会心]", coreAttribute: 0, criticalStrike: 80, recovery: 0, expertise: 0, armorPenetration: 0, color: "darkorchid"},
            {name: "金龙破虚丸[80破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 80, color: "darkorchid"},
            {name: "静夜神息丸[80调息]", coreAttribute: 0, criticalStrike: 0, recovery: 80, expertise: 0, armorPenetration: 0, color: "darkorchid"},
            {name: "星河御风丸[45专精破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 45, armorPenetration: 45, color: "darkorchid"},
            {name: "寒星流光丸[45专精会心]", coreAttribute: 0, criticalStrike: 45, recovery: 0, expertise: 45, armorPenetration: 0, color: "darkorchid"},
            {name: "碧落玄雷丸[45会心破甲]", coreAttribute: 0, criticalStrike: 45, recovery: 0, expertise: 0, armorPenetration: 45, color: "darkorchid"},
            {name: "太虚元灵丸[45会心调息]", coreAttribute: 0, criticalStrike: 45, recovery: 45, expertise: 0, armorPenetration: 0, color: "darkorchid"},
            {name: "沧澜玄灵丸[45调息专精]", coreAttribute: 0, criticalStrike: 0, recovery: 45, expertise: 45, armorPenetration: 0, color: "darkorchid"},
            {name: "傲雪凌霜丸[45调息破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 45, expertise: 0, armorPenetration: 45, color: "darkorchid"},
            {name: "无为丸[65专精]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 65, armorPenetration: 0, color: "dodgerblue"},
            {name: "云雀丸[65会心]", coreAttribute: 0, criticalStrike: 65, recovery: 0, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
            {name: "破幽丸[65破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 65, color: "dodgerblue"},
            {name: "无妄丸[65调息]", coreAttribute: 0, criticalStrike: 0, recovery: 65, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
        ]
        const currentDanYao = ref(danYaoList[0])

        const shiPinList = [
            {name: "无", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, color: "#333333"},
            {name: "佛跳墙[33调息]", coreAttribute: 0, criticalStrike: 0, recovery: 33, expertise: 0, armorPenetration: 0, color: "darkorchid"},
            {name: "单笼乳鸽汤[55核心]", coreAttribute: 55, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, color: "darkorchid"},
            {name: "如意海参[33会心]", coreAttribute: 0, criticalStrike: 33, recovery: 0, expertise: 0, armorPenetration: 0, color: "darkorchid"},
            {name: "忘忧仙茸汤[33专精]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 33, armorPenetration: 0, color: "darkorchid"},
            {name: "雪霞炖[33破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 33, color: "darkorchid"},

            {name: "云梦虾[23专精]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 23, armorPenetration: 0, color: "dodgerblue"},
            {name: "剔缕鸡[23会心]", coreAttribute: 0, criticalStrike: 23, recovery: 0, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
            {name: "九味清欢粥[23破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 23, color: "dodgerblue"},
            {name: "汤浴绣鸡[23调息]", coreAttribute: 0, criticalStrike: 0, recovery: 23, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
            {name: "雪泥客[38核心]", coreAttribute: 38, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, color: "dodgerblue"},

            {name: "阎罗饭[16专精]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 16, armorPenetration: 0, color: "dodgerblue"},
            {name: "脆琅盘[16会心]", coreAttribute: 0, criticalStrike: 16, recovery: 0, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
            {name: "太学饼[16破甲]", coreAttribute: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 16, color: "dodgerblue"},
            {name: "驱东煎[16调息]", coreAttribute: 0, criticalStrike: 0, recovery: 16, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
            {name: "满山香[27核心]", coreAttribute: 27, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0, color: "dodgerblue"},
        ]
        const currentShiPin = ref(shiPinList[0])

        const lingYao = ref(false)
        const shengShengBuXi = ref(false)

        const equipmentLevel = ref('')
        const buildName = ref("")
        const result = ref({
            physicalDefense: 0, magicDefense: 0, coreAttribute: 0, criticalStrike: 0, recovery: 0,
            expertise: 0, armorPenetration: 0, accuracy: 0, constitution: 0, HP: 0, sun: 0,
            moon: 0,
            star: 0,
        })

        const submitEquipmentFrom = ref({name: '', school: '', equipmentList: []})
        const isShowSaveImageDialog = ref(false)
        const submitEquipmentDialog = ref(false)

        const taiChuXunYuan = ref(0)
        const taiXuLiuGuang = ref(0)
        const sunHarm = ref(0)
        const moonHarm = ref(0)
        const starHarm1 = ref(0)
        const starHarm2 = ref(0)


        //一些默认属性设置
        const setDefData = () => {
            // 当前属性值
            currentEquipment.value = []
            result.value = {//物理防御
                "physicalDefense": 0,
                //法术防御
                "magicDefense": 0,
                //核心
                "coreAttribute": 0,
                //会心
                "criticalStrike": 0,
                //调息
                "recovery": 0,
                //专精
                "expertise": 0,
                //破甲
                "armorPenetration": 0,
                //命中
                "accuracy": 0,
                //体
                "constitution": 0,
                //生命
                "HP": 0
            }
            for (let i = 0; i < 10; i++) {
                currentEquipment.value.push({
                    id: 0,
                    equipmentName: "",
                    partType: 0,
                    equipageClass: 0,
                    coreAttribute: 0,
                    constitution: 0,
                    physicalDefense: 0,
                    magicDefense: 0,
                    criticalStrike: 0,
                    recovery: 0,
                    expertise: 0,
                    armorPenetration: 0,
                    accuracy: 0,
                    isRandom: 0,
                    equipmentSource: "无",
                    specialAttribute: "",
                    qualityLevel: 0,
                    isLoongSpiritEnhanced: false
                })
            }

            for (let i in enhancedAttribute.value) {
                enhancedAttribute.value[i] = {
                    coreAttribute: 0,
                    constitution: 0,
                    physicalDefense: 0,
                    magicDefense: 0,
                    criticalStrike: 0,
                    recovery: 0,
                    expertise: 0,
                    armorPenetration: 0,
                    accuracy: 0,
                }
            }
            applyAttribute()
            xingPoSelectChange()
        }
        //选择职业监听
        const selectProfessionChange = (any) => {
            currentSuitLevel.value = {}
            currentSkillTreeCriticalStrike.value = 0
            currentSkillTreeRecovery.value = 0
            currentSkillTreeExpertise.value = 0
            currentSkillTreeDefense.value = 0
            currentSkillTreeHP.value = 0
            randomAttribute1.value = {'6': {}}
            randomAttribute2.value = {'6': {}}
            randomAttribute1.value = {'7': {}}
            randomAttribute2.value = {'7': {}}
            isShowDefense.value = false;
            isShowHp.value = false
            isShowCriticalStrike.value = false;
            isShowRecovery.value = false;
            isShowExpertise.value = false;
            localStorage.setItem("currentClassName", any)
            currentEquipment.value = []
            setDefData()
            let a = ""
            let b = ""
            switch (any) {
                case "青云":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 4, 8]
                    classSchool.value = ["雷青云", "剑青云"]
                    currentClassSchool.value = "剑青云"
                    a = "雷"
                    b = "剑"
                    // this.imagePath = "url('/bgimage/bg-qy.jpg')"
                    break;
                case "焚香":
                    isShowCriticalStrike.value = true;
                    skillTreeCriticalStrike.value = [0, 4]
                    isShowRecovery.value = true;
                    skillTreeRecovery.value = [0, 4]
                    classSchool.value = ["炎焚香", "咒焚香"]
                    currentClassSchool.value = "炎焚香"
                    a = "炎"
                    b = "咒"
                    // this.imagePath = "url('/bgimage/bg-fx.jpg')"
                    break;
                case "鬼王":
                    isShowDefense.value = true
                    isShowHp.value = true
                    skillTreeDefense.value = [0, 15, 30]
                    skillTreeHp.value = [0, 10, 20]
                    classSchool.value = ["罡鬼王", "煞鬼王"]
                    currentClassSchool.value = "罡鬼王"
                    a = "罡"
                    b = "煞"
                    // this.imagePath = "url('/bgimage/bg-gw.jpg')"
                    break;
                case "合欢":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 4, 8]
                    skillTreeExpertise.value = [0, 4]
                    classSchool.value = ["影合欢", "月合欢"]
                    currentClassSchool.value = "影合欢"
                    a = "影"
                    b = "月"
                    // this.imagePath = "url('/bgimage/bg-hh.jpg')"
                    break;
                case "灵汐":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 2]
                    skillTreeExpertise.value = [0, 2]
                    classSchool.value = ["灵灵汐", "汐灵汐"]
                    currentClassSchool.value = "汐灵汐"
                    a = "灵"
                    b = "汐"
                    // this.imagePath = "url('/bgimage/bg-lx.jpg')"
                    break;
                default:
                    break;
            }
            suitLevel.value = [{name: "否", level: 0}, {name: "桑约·玄", level: 315}, {name: "桑约·极-" + a, type: classSchool.value[0], level: 325}, {name: "桑约·极-" + b, type: classSchool.value[1], level: 325}]
            getEquipmentData(any)
        }
        //获取灌注列表
        const getInlay = () => {
            http.get('/inlay/all').then((response) => {
                if (response.data.code === 200) {
                    const head = []
                    const clothing = []
                    const hand = []
                    const waist = []
                    response.data.data.forEach((item) => {
                        switch (item.partType) {
                            case 1://上身
                                clothing.push(item);
                                break;
                            case 2://头部
                                head.push(item);
                                break;
                            case 3://手部
                                hand.push(item);
                                break;
                            case 4://腰部
                                waist.push(item);
                                break;
                            default:
                                break;
                        }
                    })
                    inlayList.value.head = head
                    inlayList.value.clothing = clothing
                    inlayList.value.hand = hand
                    inlayList.value.waist = waist
                } else {
                    ElMessage.error(response.data.message);
                }
            }).catch((error) => {
                ElMessage.error(error.message);
            })
        }
        //根据职业获取对应的装备
        const getEquipmentData = (profession) => {
            http.get('/equipment/filter/' + profession).then(response => {
                if (response.data.code === 200) {
                    allEquipment.value = response.data.data.reverse();
                    let equipment = [...allEquipment.value]
                    classEquipment.value = settleEquipment(equipment)
                    // applyAttribute()
                } else {
                    ElMessage.error(response.data.message);
                }
            }).catch(error => {
                ElMessage.error('请求出错:', error);
            });
        }
        //获取境界
        const getRealmLevel = () => {
            http.get('/cultivation/all').then(response => {
                if (response.data.code === 200) {
                    realmList.value = response.data.data
                    if (response.data.data.length > 0) {
                        currentRealm.value = response.data.data[response.data.data.length - 1]
                        applyAttribute()
                    }
                } else {
                    ElMessage.error(response.data.message);
                }
            }).catch(error => {
                ElMessage.error(error.message);
            })
        }
        //整理装备数据
        const settleEquipment = (list) => {
            let zhuangbei = {
                "Weapon": [],
                "Head": [],
                "UpperBody": [],
                "Hand": [],
                "Waist": [],
                "Foot": [],
                "Charm1": [],
                "Charm2": [],
                "Seal": [],
                "Token": []
            }
            zhuangbei.Weapon = list.filter(item => item.partType === 0)
            zhuangbei.Head = list.filter(item => item.partType === 1)
            zhuangbei.UpperBody = list.filter(item => item.partType === 2)
            zhuangbei.Hand = list.filter(item => item.partType === 3)
            zhuangbei.Waist = list.filter(item => item.partType === 4)
            zhuangbei.Foot = list.filter(item => item.partType === 5)
            zhuangbei.Charm1 = list.filter(item => item.partType === 6)
            zhuangbei.Charm2 = list.filter(item => item.partType === 6)
            zhuangbei.Seal = list.filter(item => item.partType === 8)
            zhuangbei.Token = list.filter(item => item.partType === 9)
            return zhuangbei
        }
        //获取法宝列表
        const getAMagicWeapon = () => {
            http.get('/talisman/all').then(response => {
                if (response.data.code === 200) {
                    aMagicWeaponList.value.push({
                        id: 0, name: "无", criticalStrike: 0,
                        recovery: 0, expertise: 0, armorPenetration: 0, accuracy: 0
                    })
                    aMagicWeaponList.value = [...aMagicWeaponList.value, ...response.data.data];
                } else {
                    ElMessage.error(response.data.message);
                }
            }).catch(error => {
                ElMessage.error(error.message);
            })
        }
        //法宝选择监听
        const aMagicWeaponSelectChange = () => {
            applyAttribute()
        }
        //防具强化列表监听
        const armorEnhancedChange = (event, type) => {
            if (event) {
                let level = []
                const lev = (345 - currentEquipment.value[type].qualityLevel) / 10
                for (let i = 0; i <= lev; i++) {
                    level.push(i * 10)
                }
                enhancedLevel.value = level
            }
        }
        //首饰强化等级列表
        const enhancedJewelryLevelList = (isOpen, type) => {
            let level = []
            if (isOpen) {
                const lev = (345 - currentEquipment.value[type].qualityLevel) / 5
                for (let i = 0; i <= lev; i++) {
                    level.push(i * 5)
                }
            }
            return level
        }
        //根据配装的Id获取推荐配装
        const getEquipmentBuild = (id) => {
            http.get('/equipment/builds/' + id).then(response => {
                if (response.data.code === 200) {
                    //应用装备
                    currentClassName.value = response.data.data.buildClass
                    currentClassSchool.value = response.data.data.buildSchool
                    selectProfessionChange(currentClassName.value)
                    let setFusion = JSON.parse(response.data.data.setFusion)
                    let starSpirit = JSON.parse(response.data.data.starSpirit)
                    let randomValue = JSON.parse(response.data.data.randomValue)
                    let charmSetFusion = JSON.parse(response.data.data.charmSetFusion)
                    let galaxyAttribute = JSON.parse(response.data.data.galaxyAttribute)
                    currentSunMoonStarValue.value = galaxyAttribute === null ? {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0} : galaxyAttribute
                    randomAttribute1.value = randomValue === null ? {} : randomValue?.attribute1
                    randomAttribute2.value = randomValue === null ? {} : randomValue?.attribute2
                    currentEquipmentSunMoonStar.value = charmSetFusion === null ? [] : charmSetFusion
                    currentXingPo.value = starSpirit
                    xingPoSelectChange()
                    let equipments = []
                    response.data.data.equipments.forEach((any, index) => {
                        if (any.partType === 6) {
                            if (index === 6) {
                                charm1.value = any
                            } else if (index === 7) {
                                charm2.value = any
                            }
                            equipments[index] = any
                        } else {
                            equipments[any.partType] = any
                        }
                    })
                    currentEquipment.value = equipments
                    weaponEnhancedSelectChange(currentWeaponEnhancedLevel.value, 0)
                    calculateEquipment()
                    currentEquipment.value.forEach((any, index) => {
                        if (index === 0) {//武器

                        } else if (index < 6) {//只有防具才判断套装
                            if (any.equipmentSource.includes('桑约·玄套装')) {
                                currentSuitLevel.value[any.partType] = suitLevel.value[1];
                            } else if (any.equipmentSource.includes('桑约·极套装')) {
                                suitLevel.value.forEach((item, i) => {
                                    if (item.type === any.classSpecialize) {
                                        currentSuitLevel.value[any.partType] = suitLevel.value[i]
                                    }
                                });
                            } else {
                                if (setFusion !== null) {
                                    const f = setFusion.find(item => item.partType === index)
                                    if (f !== undefined) {
                                        currentSuitLevel.value[index] = f
                                        currentEquipment.value[index].classSpecialize = currentSuitLevel.value[index]?.type
                                    } else {
                                        currentSuitLevel.value[index] = suitLevel.value[0]
                                    }
                                } else {
                                    currentSuitLevel.value[index] = suitLevel.value[0]
                                }
                            }
                            let v = 345 - any.qualityLevel
                            if (any.qualityLevel >= 315) {
                                currentArmorEnhancedLevel.value[index] = v
                            }
                            armorEnhancedSelectChange(index)
                        } else {//首饰
                            if (any.qualityLevel < 345) {
                                currentJewelryEnhancedLevel.value[index] = 345 - any.qualityLevel
                            } else {
                                currentJewelryEnhancedLevel.value[index] = 0
                            }
                            randomAttributeChange1(randomAttribute1.value[index], index)
                            randomAttributeChange2(randomAttribute2.value[index], index)
                            JewelryEnhancedSelectChange(index)
                        }
                    })

                    calculateSuit()
                    currentAMagicWeapon.value = response.data.data.talisman
                    currentSkillTreeCriticalStrike.value = response.data.data.skillTree.criticalStrike
                    currentSkillTreeRecovery.value = response.data.data.skillTree.recovery
                    currentSkillTreeExpertise.value = response.data.data.skillTree.expertise
                    currentSkillTreeDefense.value = response.data.data.skillTree.defense
                    currentSkillTreeHP.value = response.data.data.skillTree.hp

                    currentInlay.value.head = response.data.data.inlays.filter(inlay => inlay.partType === 2)
                    currentInlay.value.clothing = response.data.data.inlays.filter(inlay => inlay.partType === 1)
                    currentInlay.value.hand = response.data.data.inlays.filter(inlay => inlay.partType === 3)
                    currentInlay.value.waist = response.data.data.inlays.filter(inlay => inlay.partType === 4)

                    inlaySelectChange()
                } else {
                    ElMessage.error(response.data.message);
                }
            })
        }

        //星魄选择监听
        const xingPoSelectChange = () => {
            let totalCoreAttribute = 0
            let criticalStrike
            let expertise
            let armorPenetration
            let recovery
            let totalHP = 0;
            for (let i in currentXingPo.value) {
                console.log(i, currentXingPo.value[i].coreAttribute)
                totalCoreAttribute += currentXingPo.value[i].coreAttribute
                totalHP += currentXingPo.value[i].HP
            }
            criticalStrike = currentXingPo.value['青龙'].attribute * 3
            recovery = currentXingPo.value['白虎'].attribute * 3
            armorPenetration = currentXingPo.value['玄武'].attribute * 3
            expertise = currentXingPo.value['朱雀'].attribute * 3

            totalXingPoAttribute.value.coreAttribute = totalCoreAttribute
            totalXingPoAttribute.value.criticalStrike = criticalStrike
            totalXingPoAttribute.value.recovery = recovery
            totalXingPoAttribute.value.armorPenetration = armorPenetration
            totalXingPoAttribute.value.expertise = expertise
            totalXingPoAttribute.value.hp = totalHP
            console.log(totalXingPoAttribute.value)
            applyAttribute()
        }

        // let cDanYao = danYaoList[0]
        const danYaoSelectChange = (event) => {
            console.log(event)
            // if (event.name === "无") {
            //     result.value.coreAttribute.sub(cDanYao.coreAttribute)
            //     result.value.criticalStrike.sub(cDanYao.criticalStrike)
            //     result.value.recovery.sub(cDanYao.recovery)
            //     result.value.expertise.sub(cDanYao.expertise)
            //     result.value.armorPenetration.sub(cDanYao.armorPenetration)
            // } else {
            //     result.value.coreAttribute.sub(cDanYao.coreAttribute)
            //     result.value.criticalStrike.sub(cDanYao.criticalStrike)
            //     result.value.recovery.sub(cDanYao.recovery)
            //     result.value.expertise.sub(cDanYao.expertise)
            //     result.value.armorPenetration.sub(cDanYao.armorPenetration)
            //
            //     result.value.coreAttribute.add(event.coreAttribute)
            //     result.value.criticalStrike.add(event.criticalStrike)
            //     result.value.recovery.add(event.recovery)
            //     result.value.expertise.add(event.expertise)
            //     result.value.armorPenetration.add(event.armorPenetration)
            // }
            // cDanYao = event
            applyAttribute()
        }
        // let cShiPin = shiPinList[0]
        const shiPinSelectChange = (event) => {
            // if (event.name === "无") {
            //     result.value.coreAttribute.sub(cShiPin.coreAttribute)
            //     result.value.criticalStrike.sub(cShiPin.criticalStrike)
            //     result.value.recovery.sub(cShiPin.recovery)
            //     result.value.expertise.sub(cShiPin.expertise)
            //     result.value.armorPenetration.sub(cShiPin.armorPenetration)
            // } else {
            //     result.value.coreAttribute.sub(cShiPin.coreAttribute)
            //     result.value.criticalStrike.sub(cShiPin.criticalStrike)
            //     result.value.recovery.sub(cShiPin.recovery)
            //     result.value.expertise.sub(cShiPin.expertise)
            //     result.value.armorPenetration.sub(cShiPin.armorPenetration)
            //
            //     result.value.coreAttribute.add(event.coreAttribute)
            //     result.value.criticalStrike.add(event.criticalStrike)
            //     result.value.recovery.add(event.recovery)
            //     result.value.expertise.add(event.expertise)
            //     result.value.armorPenetration.add(event.armorPenetration)
            // }
            // cShiPin = event
            applyAttribute()
        }
        const lingYaoSelectChange = (event) => {
            console.log(event)
            // if (event) {
            //     result.value.coreAttribute.add(575)
            // } else {
            //     result.value.coreAttribute.sub(575)
            // }
            applyAttribute()
        }
        // let cA = 0
        const shengShengSelectChange = (event) => {
            console.log(event)

            // if (event) {
            //     cA = result.value.coreAttribute.valueOf() * 0.2
            //     result.value.coreAttribute.add(cA)
            // } else {
            //     result.value.coreAttribute.sub(cA)
            // }
            applyAttribute()
        }

        //根据等级搜索装备
        const equipmentLevelChange = (level) => {
            if (level.length === 0) {
                let equipment = [...allEquipment.value]
                classEquipment.value = settleEquipment(equipment)
            } else {
                let equipment = allEquipment.value.filter(item => item.qualityLevel.toString() >= level)
                this.classEquipment = settleEquipment(equipment)
            }
        }
        //选择装备监听
        const equipmentSelectChange = (any) => {
            if (any.partType === 6) {//先选第二个护符，后选第一个护符
                randomAttribute1.value = {'6': {}}
                randomAttribute2.value = {'6': {}}
                if (currentEquipment.value[6].equipmentName?.includes("神兮无间") && currentEquipmentSunMoonStar.value[6]?.type >= 0) {
                    currentEquipment.value[6].accuracy = 0
                }
                if (currentEquipment.value[7].id > 0) {//第二个护符已经选了
                    if (currentEquipment.value[7].id === any.id) {//第一个护符和第二个选择护符一样，把第二个护符调换至第一个
                        [charm1.value, currentEquipment.value[7]] = [currentEquipment.value[7], charm1.value];
                        charm2.value = {
                            id: 0, equipmentName: "", partType: 0, equipageClass: 0, coreAttribute: 0, constitution: 0,
                            physicalDefense: 0, magicDefense: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0,
                            accuracy: 0, equipmentSource: "无", qualityLevel: 0, isLoongSpiritEnhanced: false
                        }
                        currentEquipmentSunMoonStar.value[6] = currentEquipmentSunMoonStar.value[7]
                        currentEquipmentSunMoonStar.value[7] = sunMoonStar[0]
                    }
                }
                if (any.isRandom && currentEquipmentSunMoonStar.value[6]?.type >= 0) {
                    currentEquipmentSunMoonStar.value[6] = sunMoonStar[0]
                }
            }
            if (any.partType > 0 && any.partType < 6) {
                if (any.equipmentSource.includes('桑约·玄套装')) {
                    currentSuitLevel.value[any.partType] = suitLevel.value[1]
                } else if (any.equipmentSource.includes('桑约·极套装')) {
                    suitLevel.value.forEach((item, index) => {
                        if (item.type === any.classSpecialize) {
                            currentSuitLevel.value[any.partType] = suitLevel.value[index]
                        }
                    })
                } else {
                    currentSuitLevel.value[any.partType] = suitLevel.value[0]
                }
            }

            if (any.galaxyType > 0) {
                currentSunMoonStarValue.value[any.partType] = any.galaxyMin
            } else {
                currentSunMoonStarValue.value[any.partType] = 0
            }
            calculateSuit()

            charm1.value = any
            //每次选择装备，让龙魂符强化为0
            if (any.partType === 0) {
                currentWeaponEnhancedLevel.value = 0
            } else if (any.partType < 6) {
                currentArmorEnhancedLevel.value[any.partType] = 0
                armorEnhancedSelectChange(any.partType)
            } else {
                currentJewelryEnhancedLevel.value[any.partType] = 0
                JewelryEnhancedSelectChange(any.partType)
                console.log(currentJewelryEnhancedLevel.value)
            }
            calculateEquipment()
            inlaySelectChange()
        }
        //选择装备-第二个护符
        const equipmentSelectChange1 = (any) => {
            randomAttribute1.value = {'7': {}}
            randomAttribute2.value = {'7': {}}
            if (currentEquipment.value[7].equipmentName?.includes("神兮无间") && currentEquipmentSunMoonStar.value[7]?.type >= 0) {
                currentEquipment.value[7].accuracy = 0
            }
            if (any.isRandom && currentEquipmentSunMoonStar.value[7]?.type >= 0) {
                currentEquipmentSunMoonStar.value[7] = sunMoonStar[0]
            }
            if (any.partType === 6) {//先选第一个护符，后选第二个护符
                if (currentEquipment.value[6].id > 0) {//第一个护符已经选了
                    if (currentEquipment.value[6].id === any.id) {//第二个护符和第一个护符一样，把第一个护符调换至第二个
                        [currentEquipment.value[6], charm2.value] = [charm2.value, currentEquipment.value[6]];
                        charm1.value = {
                            id: 0, equipmentName: "", partType: 0, equipageClass: 0, coreAttribute: 0, constitution: 0,
                            physicalDefense: 0, magicDefense: 0, criticalStrike: 0, recovery: 0, expertise: 0, armorPenetration: 0,
                            accuracy: 0, equipmentSource: "无", qualityLevel: 0, isLoongSpiritEnhanced: false
                        }
                        currentEquipmentSunMoonStar.value[7] = currentEquipmentSunMoonStar.value[6]
                        currentEquipmentSunMoonStar.value[6] = sunMoonStar[0]
                    }
                }
            }
            charm2.value = any
            //每次选择装备，让龙魂符强化为0
            currentJewelryEnhancedLevel.value[7] = 0
            JewelryEnhancedSelectChange(7)
            calculateEquipment()
            applyAttribute()
            console.log(currentJewelryEnhancedLevel.value)
        }
        //选择灌注
        const inlaySelectChange = () => {
            let inlayList = []
            for (let i in currentInlay.value.head) {
                let a = {...currentInlay.value.head[i]}
                //如果头盔是世界boss的，则增加灌注属性，这里不用id来判断的原因是因为，每个职业都有一个世界boss的装备，判断起来太麻烦，所以干脆用名称判断
                if (currentEquipment.value[1].equipmentName?.includes('倏忽无同')) {
                    a.coreAttribute = (currentInlay.value.head[i].coreAttribute * 1.2).toFixed(0)
                } else {
                    a = currentInlay.value.head[i]
                }
                inlayList.push(a)
            }
            for (let l in currentInlay.value.clothing) {
                let a = {...currentInlay.value.clothing[l]}
                //如果上衣是世界boss的，则增加灌注属性，这里不用id来判断的原因是因为，每个职业都有一个世界boss的装备，判断起来太麻烦，所以干脆用名称判断
                if (currentEquipment.value[2].equipmentName?.includes('倏忽无同')) {
                    a.blood = (a.blood * 1.35).toFixed(0)
                } else {
                    a = currentInlay.value.clothing[l]
                }
                inlayList.push(a)
            }
            for (let j in currentInlay.value.hand) {
                let a = {...currentInlay.value.hand[j]}
                //如果护腕是世界boss的，则增加灌注属性，这里不用id来判断的原因是因为，每个职业都有一个世界boss的装备，判断起来太麻烦，所以干脆用名称判断
                if (currentEquipment.value[3].equipmentName?.includes('倏忽无同')) {
                    a.criticalStrike = currentInlay.value.hand[j].criticalStrike * 1.5
                    a.expertise = currentInlay.value.hand[j].expertise * 1.5
                    a.armorPenetration = currentInlay.value.hand[j].armorPenetration * 1.5
                    a.recovery = currentInlay.value.hand[j].recovery * 1.5
                    a.accuracy = currentInlay.value.hand[j].accuracy * 1.5
                } else {
                    a = currentInlay.value.hand[j]
                }
                inlayList.push(a)
            }
            for (let k in currentInlay.value.waist) {//处理腰带灌注
                let a = {...currentInlay.value.waist[k]}
                //如果腰带是世界boss的，则增加灌注属性，这里不用id来判断的原因是因为，每个职业都有一个世界boss的装备，判断起来太麻烦，所以干脆用名称判断
                if (currentEquipment.value[4].equipmentName?.includes('倏忽无同')) {
                    a.criticalStrike = currentInlay.value.waist[k].criticalStrike * 1.5
                    a.expertise = currentInlay.value.waist[k].expertise * 1.5
                    a.armorPenetration = currentInlay.value.waist[k].armorPenetration * 1.5
                    a.recovery = currentInlay.value.waist[k].recovery * 1.5
                    a.accuracy = currentInlay.value.waist[k].accuracy * 1.5
                } else {
                    a = currentInlay.value.waist[k]
                }
                inlayList.push(a)
            }
            let coreAttribute = 0;
            let criticalStrike = 0
            let expertise = 0
            let armorPenetration = 0
            let recovery = 0
            let accuracy = 0
            let hp = 0
            inlayList.forEach(inlay => {
                coreAttribute += inlay.coreAttribute
                criticalStrike += inlay.criticalStrike
                expertise += inlay.expertise
                armorPenetration += inlay.armorPenetration
                recovery += inlay.recovery
                accuracy += inlay.accuracy
                hp += inlay.blood
            })
            totalInlayAttribute.value.coreAttribute = coreAttribute
            totalInlayAttribute.value.criticalStrike = criticalStrike
            totalInlayAttribute.value.expertise = expertise
            totalInlayAttribute.value.armorPenetration = armorPenetration
            totalInlayAttribute.value.recovery = recovery
            totalInlayAttribute.value.accuracy = accuracy
            totalInlayAttribute.value.hp = hp
            applyAttribute()
        }
        //选择是否为套装
        const suitChange = (_isSuit, type) => {
            currentEquipment.value[type].classSpecialize = currentSuitLevel.value[type].type
            calculateSuit()
            applyAttribute()
        }
        //日月星数值
        const sunMoonStarNumberChange = (event, type) => {
            applyAttribute()
        }
        //日月星贴膜
        const sunMoonStarChange = (event, type) => {
            console.log(event, currentEquipment.value[type])
            if (currentEquipment.value[type].equipmentName?.includes("神兮无间")) {
                if (event.type >= 0) {
                    currentEquipment.value[type].accuracy = 0;
                } else {
                    currentEquipment.value[type].accuracy = -39;
                }
            }
            calculateEquipment()
            applyAttribute()
        }
        //日月星护符自定义属性1选择
        const randomAttributeChange1 = (event, type) => {
            if (event === undefined || event.type === undefined) {
                return
            }
            let a = event?.value
            /** 1.05 ** (this.currentEnhanced[type] / 5)*/
            let max = Math.max(currentEquipment.value[type].criticalStrike, currentEquipment.value[type].recovery, currentEquipment.value[type].expertise,
                currentEquipment.value[type].armorPenetration, currentEquipment.value[type].accuracy)
            if (max > 200) {//说明装备之前有值
                switch (max) {//把之前的值清空
                    case currentEquipment.value[type].criticalStrike:
                        currentEquipment.value[type].criticalStrike = 0
                        break
                    case currentEquipment.value[type].recovery:
                        currentEquipment.value[type].recovery = 0
                        break
                    case currentEquipment.value[type].expertise:
                        currentEquipment.value[type].expertise = 0
                        break
                    case currentEquipment.value[type].armorPenetration:
                        currentEquipment.value[type].armorPenetration = 0
                        break
                    case currentEquipment.value[type].accuracy:
                        currentEquipment.value[type].accuracy = 0
                        break
                }
            }
            switch (event?.type) {
                case 0://会心
                    currentEquipment.value[type].criticalStrike = a
                    break
                case 1://调息
                    currentEquipment.value[type].recovery = a
                    break
                case 2://专精
                    currentEquipment.value[type].expertise = a
                    break
                case 3://破甲
                    currentEquipment.value[type].armorPenetration = a
                    break
                case 4://命中
                    currentEquipment.value[type].accuracy = a
                    break
            }
            JewelryEnhancedSelectChange(type)
            calculateEquipment()
            applyAttribute()
        }
        //日月星护符自定义属性2选择
        const randomAttributeChange2 = (event, type) => {
            if (event === undefined || event.type === undefined) {
                return
            }
            let a = event?.value
            /** 1.05 ** (this.currentEnhanced[type] / 5)*/
                //这里获取最小值要排除0
            let arr = [currentEquipment.value[type].criticalStrike, currentEquipment.value[type].recovery, currentEquipment.value[type].expertise,
                    currentEquipment.value[type].armorPenetration, currentEquipment.value[type].accuracy]
            let arr1 = arr.filter(x => x > 0)
            let min = Math.min(...arr1)
            if (min < 200) {//说明之前有值
                switch (min) {//把之前的值清空
                    case currentEquipment.value[type].criticalStrike:
                        currentEquipment.value[type].criticalStrike = 0
                        break
                    case currentEquipment.value[type].recovery:
                        currentEquipment.value[type].recovery = 0
                        break
                    case currentEquipment.value[type].expertise:
                        currentEquipment.value[type].expertise = 0
                        break
                    case currentEquipment.value[type].armorPenetration:
                        currentEquipment.value[type].armorPenetration = 0
                        break
                    case currentEquipment.value[type].accuracy:
                        currentEquipment.value[type].accuracy = 0
                        break
                }
            }
            switch (event?.type) {
                case 0://会心
                    currentEquipment.value[type].criticalStrike = a
                    break
                case 1://调息
                    currentEquipment.value[type].recovery = a
                    break
                case 2://专精
                    currentEquipment.value[type].expertise = a
                    break
                case 3://破甲
                    currentEquipment.value[type].armorPenetration = a
                    break
                case 4://命中
                    currentEquipment.value[type].accuracy = a
                    break
            }
            JewelryEnhancedSelectChange(type)
            calculateEquipment()
            applyAttribute()
        }
        //神兵武器强化
        const weaponEnhancedSelectChange = (event, _type) => {
            // 配置数据抽象
            const eventConfigs = [
                {core: 819, con: 310, attr: 248}, {core: 826, con: 313, attr: 251},
                {core: 834, con: 316, attr: 252}, {core: 841, con: 318, attr: 254},
                {core: 849, con: 322, attr: 257}, {core: 857, con: 324, attr: 259},
                {core: 865, con: 327, attr: 263}, {core: 873, con: 331, attr: 264},
                {core: 881, con: 333, attr: 266}, {core: 889, con: 336, attr: 269},
                {core: 897, con: 340, attr: 271}
            ];

            // 统一处理逻辑
            const config = eventConfigs[event];
            const equipment = currentEquipment.value[0];

            equipment.coreAttribute = config.core;
            equipment.constitution = config.con;

            ['criticalStrike', 'recovery', 'expertise', 'armorPenetration', 'accuracy']
                .forEach(prop => {
                    equipment[prop] = equipment[prop] > 0 ? config.attr : equipment[prop];
                });
            calculateEquipment()
            applyAttribute()
        }

        //计算每个防具强化后的额外属性
        const armorEnhancedSelectChange = (type) => {
            let coefficient = 1.095
            // if (type === 1 || type === 2 || type === 5) {
            //     coefficient = 1.095
            // } else {
            //     coefficient = 1.1
            // }
            let coreAttribute = (currentEquipment.value[type].coreAttribute * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].coreAttribute
            let constitution = currentEquipment.value[type].constitution < 0 ? 0 : (currentEquipment.value[type].constitution * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].constitution
            let criticalStrike = currentEquipment.value[type].criticalStrike < 0 ? 0 : (currentEquipment.value[type].criticalStrike * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].criticalStrike
            let recovery = currentEquipment.value[type].recovery < 0 ? 0 : (currentEquipment.value[type].recovery * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].recovery
            let expertise = currentEquipment.value[type].expertise < 0 ? 0 : (currentEquipment.value[type].expertise * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].expertise
            let armorPenetration = currentEquipment.value[type].armorPenetration < 0 ? 0 : (currentEquipment.value[type].armorPenetration * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].armorPenetration
            let accuracy = currentEquipment.value[type].accuracy < 0 ? 0 : (currentEquipment.value[type].accuracy * (coefficient ** (currentArmorEnhancedLevel.value[type] / 10))) - currentEquipment.value[type].accuracy
            console.log(criticalStrike, recovery, expertise, armorPenetration, accuracy)
            console.log(customToFixed(armorPenetration))
            /*
            把当前选择龙魂符强化的部位的每个属性数值存放进集合对应的位置中
            如果数值为负数则不计算，只返回数值本身
             */
            enhancedAttribute.value[type] = {
                coreAttribute: customToFixed(coreAttribute),
                constitution: customToFixed(constitution),
                criticalStrike: customToFixed(criticalStrike),
                recovery: customToFixed(recovery),
                expertise: customToFixed(expertise),
                armorPenetration: customToFixed(armorPenetration),
                accuracy: customToFixed(accuracy),

            }
            calculateEnhancedAttribute()
        }

        function customToFixed(num) {
            let n = Math.round((num + Number.EPSILON) * Math.pow(10, 1)) / Math.pow(10, 1);
            return Math.round((n + Number.EPSILON) * Math.pow(10, 0)) / Math.pow(10, 0);
        }

        //计算每个首饰强化后的额外属性
        const JewelryEnhancedSelectChange = (type) => {
            /*
            把当前选择龙魂符强化的部位的每个属性数值存放进集合对应的位置中
            如果数值为负数则不计算，只返回数值本身
             */
            let coreAttribute = (currentEquipment.value[type].coreAttribute * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].coreAttribute
            let constitution = currentEquipment.value[type].constitution < 0 ? 0 : (currentEquipment.value[type].constitution * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].constitution
            let criticalStrike = currentEquipment.value[type].criticalStrike < 0 ? 0 : (currentEquipment.value[type].criticalStrike * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].criticalStrike
            let recovery = currentEquipment.value[type].recovery < 0 ? 0 : (currentEquipment.value[type].recovery * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].recovery
            let expertise = currentEquipment.value[type].expertise < 0 ? 0 : (currentEquipment.value[type].expertise * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].expertise
            let armorPenetration = currentEquipment.value[type].armorPenetration < 0 ? 0 : (currentEquipment.value[type].armorPenetration * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].armorPenetration
            let accuracy = currentEquipment.value[type].accuracy < 0 ? 0 : (currentEquipment.value[type].accuracy * (1.05 ** (currentJewelryEnhancedLevel.value[type] / 5))).toFixed(0) - currentEquipment.value[type].accuracy
            enhancedAttribute.value[type] = {
                coreAttribute: customToFixed(coreAttribute),
                constitution: customToFixed(constitution),
                criticalStrike: customToFixed(criticalStrike),
                recovery: customToFixed(recovery),
                expertise: customToFixed(expertise),
                armorPenetration: customToFixed(armorPenetration),
                accuracy: customToFixed(accuracy),
            }
            calculateEnhancedAttribute()
        }
        //计算装备强化的属性
        const calculateEnhancedAttribute = () => {
            let array = enhancedAttribute.value
            let coreAttribute = 0
            let constitution = 0
            let criticalStrike = 0
            let recovery = 0
            let expertise = 0
            let armorPenetration = 0
            let accuracy = 0
            for (const i in array) {
                coreAttribute += array[i].coreAttribute
                constitution += array[i].constitution
                criticalStrike += array[i].criticalStrike
                recovery += array[i].recovery
                expertise += array[i].expertise
                armorPenetration += array[i].armorPenetration
                accuracy += array[i].accuracy
            }
            totalEnhancedAttribute.value.coreAttribute = coreAttribute
            totalEnhancedAttribute.value.constitution = constitution
            totalEnhancedAttribute.value.criticalStrike = criticalStrike
            totalEnhancedAttribute.value.recovery = recovery
            totalEnhancedAttribute.value.expertise = expertise
            totalEnhancedAttribute.value.armorPenetration = armorPenetration
            totalEnhancedAttribute.value.accuracy = accuracy
            calculateEquipment()
            applyAttribute()
        }
        //计算套装
        const calculateSuit = () => {
            let s315 = 0
            for (const [_key, value] of Object.entries(currentSuitLevel.value)) {
                if (value.level === 315) {
                    s315++
                }
            }
            suitNumber315.value = s315

            suitSize1.value = 0
            suitSize2.value = 0
            switch (currentClassName.value) {
                case "青云":
                    classSchool.value = ["雷青云", "剑青云"]
                    suitSize1.value = currentEquipment.value.filter(value => value.classSpecialize === "雷青云").length
                    suitSize2.value = currentEquipment.value.filter(value => value.classSpecialize === "剑青云").length
                    if (suitSize1.value >= 2) {
                        suitAttribute1.value = [
                            "2：引雷诀、真霆雷动、神剑御雷真诀造成的伤害提高15%",
                            "4：释放真霆雷动获得1层【纵溢】效果，释放神剑御雷真诀获得3层【纵溢】效果，消耗【纵溢】效果可无视消耗释放一次引雷诀，【雷元爆发】状态下，消耗【纵溢】效果的引雷诀造成伤害提高50%"
                        ]
                    }
                    if (suitSize2.value >= 2) {
                        suitAttribute2.value = [
                            "2：道剑纵横、穿星造成的伤害提高20%；剑扫六合造成的伤害提高30%",
                            "4：释放剑心通明和寰宇千锋时，分别获得1/2层【凌绝】效果，消耗【凌绝】效果可无视冷却释放一次道剑纵横，通过此效果获得的道剑纵横无法使自身获得无敌效果；道剑纵横使自身获得3秒剑心通明或6秒寰宇千锋效果（取决于自身所习得的秘技）",
                        ]
                    }
                    break;
                case "焚香":
                    classSchool.value = ["炎焚香", "咒焚香"]
                    suitSize1.value = currentEquipment.value.filter(value => value.classSpecialize === "炎焚香").length
                    suitSize2.value = currentEquipment.value.filter(value => value.classSpecialize === "咒焚香").length
                    if (suitSize1.value >= 2) {
                        suitAttribute1.value = [
                            "2：炎龙降世或轰焱的会心率提升15%",
                            "4：释放炎龙印刻后，6秒内自身会心率增加40%",
                        ]
                    }
                    if (suitSize2.value >= 2) {
                        suitAttribute2.value = [
                            "2：玄阳天律会心率增加30%",
                            "4：每使用一次灵引，玄阳天律冷却减少3秒"
                        ]
                    }
                    break;
                case "鬼王":
                    classSchool.value = ["罡鬼王", "煞鬼王"]
                    suitSize1.value = currentEquipment.value.filter(value => value.classSpecialize === "罡鬼王").length
                    suitSize2.value = currentEquipment.value.filter(value => value.classSpecialize === "煞鬼王").length
                    if (suitSize1.value >= 2) {
                        suitAttribute1.value = [
                            "2：追魂斩造成的伤害提高20%，并恢复自身等同于物理攻击的气血",
                            "4：聚灵斩充能层数增加1次，聚灵斩每消耗一层破绽，减少1秒明王降世咒冷却时间"
                        ]
                    }
                    if (suitSize2.value >= 2) {
                        suitAttribute2.value = [
                            "2：鬼王每秒额外恢复30点魔性",
                            "4：鬼斩、湮魂爪每次命中减少魔性大发、明王降世咒技能0.3秒冷却时间，魔性大发、明王降世咒期间对怪物造成伤害增加25%",
                        ]
                    }
                    break;
                case "合欢":
                    classSchool.value = ["影合欢", "月合欢"]
                    suitSize1.value = currentEquipment.value.filter(value => value.classSpecialize === "影合欢").length
                    suitSize2.value = currentEquipment.value.filter(value => value.classSpecialize === "月合欢").length
                    if (suitSize1.value >= 2) {
                        suitAttribute1.value = [
                            "2：拂袖千星的月能消耗提高20点，拂袖千星、拂袖千星·影的伤害提高25%",
                            "4：每次释放影舞，下次影舞、影舞·影伤害提高60%，并获得拂袖千星·暗香"
                        ]
                    }
                    if (suitSize2.value >= 2) {
                        suitAttribute2.value = [
                            "2：月刃之息伤害提高15%",
                            "4：月无情和月袭的会心率提高8%，并且每释放5次月刃之息获得一个不消耗冷却、不消耗月能的月无情和月袭",
                        ]
                    }
                    break;
                case "灵汐":
                    classSchool.value = ["灵灵汐", "汐灵汐"]
                    suitSize1.value = currentEquipment.value.filter(value => value.classSpecialize === "灵灵汐").length
                    suitSize2.value = currentEquipment.value.filter(value => value.classSpecialize === "汐灵汐").length
                    if (suitSize1.value >= 2) {
                        suitAttribute1.value = [
                            "2：对敌人释放甘霖时恢复自身1枚鱼灵；甘霖每次造成伤害时，自身获得2层【怒潮】效果，灵爆会消耗所有【怒潮】效果，每层【怒潮】使敌人额外受到86水属性伤害，此伤害受到自身专精率影响",
                            "4：碎雨和潮歌每次造成伤害时，为自身叠加1层【怒潮】效果；进入战斗时，立刻获得40层【怒潮】效果",
                        ]
                    }
                    if (suitSize2.value >= 2) {
                        suitAttribute2.value = [
                            "2：甘霖为目标添加【飞鳐守护】效果，使其在下次受到伤害时恢复2532气血",
                            "4：消耗【飞鳐守护】使目标受到自身的气血恢复效果提高10%，持续10秒。"
                        ]
                    }
                    break;
                default:
                    break;
            }
            //根据套装，判断当前职业专精
            if (suitSize1.value > suitSize2.value) {
                currentClassSchool.value = classSchool.value[0]
            } else if (suitSize1.value < suitSize2.value) {
                currentClassSchool.value = classSchool.value[1]
            } else {
                currentClassSchool.value = classSchool.value[0]
            }
            selectSchoolChange(currentClassSchool.value)
        }
        //选择职业专精监听
        const selectSchoolChange = (any) => {
            currentSkillTreeCriticalStrike.value = 0
            currentSkillTreeExpertise.value = 0
            currentSkillTreeDefense.value = 0
            currentSkillTreeRecovery.value = 0
            currentSkillTreeHP.value = 0
            isShowDefense.value = false;
            isShowCriticalStrike.value = false;
            isShowRecovery.value = false;
            isShowExpertise.value = false;
            isShowHp.value = false
            switch (any) {
                case "雷青云":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 2]
                    skillTreeRecovery.value = [0, 2]
                    skillTreeExpertise.value = [0, 2]
                    break;
                case "剑青云":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 4, 8]
                    break;
                case "炎焚香":
                    isShowCriticalStrike.value = true;
                    skillTreeCriticalStrike.value = [0, 4]
                    isShowRecovery.value = true;
                    skillTreeRecovery.value = [0, 4]
                    break;
                case "咒焚香":
                    isShowCriticalStrike.value = true;
                    skillTreeCriticalStrike.value = [0, 4]
                    isShowRecovery.value = true;
                    skillTreeRecovery.value = [0, 4]
                    break;
                case "罡鬼王":
                    isShowHp.value = true
                    isShowDefense.value = true
                    skillTreeDefense.value = [0, 15, 30]
                    skillTreeHp.value = [0, 10, 20]
                    break;
                case "煞鬼王":
                    isShowCriticalStrike.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 2.5, 5]
                    skillTreeExpertise.value = [0, 3, 6]
                    break;
                case "影合欢":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 4, 8]
                    skillTreeExpertise.value = [0, 4]
                    break;
                case "月合欢":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 4, 8]
                    skillTreeExpertise.value = [0, 4]
                    break;
                case "灵灵汐":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 2]
                    skillTreeExpertise.value = [0, 2]
                    break;
                case "汐灵汐":
                    isShowCriticalStrike.value = true;
                    isShowRecovery.value = true;
                    isShowExpertise.value = true;
                    skillTreeCriticalStrike.value = [0, 4, 8]
                    skillTreeRecovery.value = [0, 2]
                    skillTreeExpertise.value = [0, 2]
                    break;
                default:
                    break;
            }
        }

        //计算装备选择完毕后的属性总和
        const calculateEquipment = () => {
            totalAttribute.value.coreAttribute = 0
            totalAttribute.value.constitution = 0
            totalAttribute.value.physicalDefense = 0
            totalAttribute.value.magicDefense = 0
            totalAttribute.value.criticalStrike = 0
            totalAttribute.value.recovery = 0
            totalAttribute.value.expertise = 0
            totalAttribute.value.armorPenetration = 0
            totalAttribute.value.accuracy = 0
            console.log(currentEquipment.value)
            currentEquipment.value.forEach((item) => {
                totalAttribute.value.coreAttribute += item.coreAttribute
                totalAttribute.value.constitution += item.constitution
                totalAttribute.value.physicalDefense += item.physicalDefense
                totalAttribute.value.magicDefense += item.magicDefense
                totalAttribute.value.criticalStrike += item.criticalStrike
                totalAttribute.value.recovery += item.recovery
                totalAttribute.value.expertise += item.expertise
                totalAttribute.value.armorPenetration += item.armorPenetration
                totalAttribute.value.accuracy += item.accuracy
            })

        }

        //应用属性
        const applyAttribute = () => {
            let res = {
                physicalDefense: 0, magicDefense: 0, coreAttribute: 0, criticalStrike: 0, recovery: 0,
                expertise: 0, armorPenetration: 0, accuracy: 0, constitution: 0, HP: 0, sun: 0, moon: 0, star: 0,
            }
            if (currentClassName.value === "鬼王" && currentClassSchool.value === "罡鬼王") {//计算鬼王天书防御
                res.physicalDefense = basics.value.physicalDefense + totalAttribute.value.physicalDefense
                res.magicDefense = basics.value.magicDefense + totalAttribute.value.magicDefense

                res.physicalDefense = res.physicalDefense * 1.5 + res.physicalDefense * (currentSkillTreeDefense.value / 100)
                res.magicDefense = res.magicDefense * 1.5 + res.magicDefense * (currentSkillTreeDefense.value / 100)
            } else {
                currentSkillTreeDefense.value = 0
                res.physicalDefense = basics.value.physicalDefense + totalAttribute.value.physicalDefense
                res.magicDefense = basics.value.magicDefense + totalAttribute.value.magicDefense
            }
            res.coreAttribute = basics.value.coreAttribute + totalAttribute.value.coreAttribute +
                totalEnhancedAttribute.value.coreAttribute + currentRealm.value.coreAttribute +
                totalInlayAttribute.value.coreAttribute + aMagicWeapon.coreAttribute + totalXingPoAttribute.value.coreAttribute
            res.criticalStrike = basics.value.criticalStrike + totalAttribute.value.criticalStrike +
                totalEnhancedAttribute.value.criticalStrike + totalInlayAttribute.value.criticalStrike +
                totalXingPoAttribute.value.criticalStrike + (currentAMagicWeapon.value?.criticalStrike || 0)
            res.recovery = totalAttribute.value.recovery + totalEnhancedAttribute.value.recovery +
                totalInlayAttribute.value.recovery + totalXingPoAttribute.value.recovery + (currentAMagicWeapon.value?.recovery || 0)
            res.expertise = totalAttribute.value.expertise + totalEnhancedAttribute.value.expertise +
                totalInlayAttribute.value.expertise + totalXingPoAttribute.value.expertise + (currentAMagicWeapon.value?.expertise || 0)
            res.armorPenetration = totalAttribute.value.armorPenetration + totalEnhancedAttribute.value.armorPenetration +
                totalInlayAttribute.value.armorPenetration + totalXingPoAttribute.value.armorPenetration +
                (currentAMagicWeapon.value?.armorPenetration || 0)
            res.accuracy = totalAttribute.value.accuracy + totalEnhancedAttribute.value.accuracy +
                totalInlayAttribute.value.accuracy + (currentAMagicWeapon.value?.accuracy || 0)
            res.constitution = basics.value.constitution + totalAttribute.value.constitution + totalEnhancedAttribute.value.constitution + currentRealm.value.constitution
            res.HP = (res.constitution * 10 + aMagicWeapon.HP + totalInlayAttribute.value.hp + totalXingPoAttribute.value.hp)
            if (currentClassName.value === "鬼王" && currentClassSchool.value === "罡鬼王") {
                res.HP = res.HP + (res.HP * 0.3) + (res.HP * (currentSkillTreeHP.value / 100))
            }
            console.log(res)
            result.value.coreAttribute = new Calculator(res.coreAttribute).add(currentDanYao.value.coreAttribute).add(currentShiPin.value.coreAttribute)
            result.value.physicalDefense = new Calculator(res.physicalDefense)
            result.value.magicDefense = new Calculator(res.magicDefense)
            result.value.criticalStrike = new Calculator(res.criticalStrike).add(currentDanYao.value.criticalStrike).add(currentShiPin.value.criticalStrike)
            result.value.recovery = new Calculator(res.recovery).add(currentDanYao.value.recovery).add(currentShiPin.value.recovery)
            result.value.expertise = new Calculator(res.expertise).add(currentDanYao.value.expertise).add(currentShiPin.value.expertise)
            result.value.armorPenetration = new Calculator(res.armorPenetration).add(currentDanYao.value.armorPenetration).add(currentShiPin.value.armorPenetration)
            result.value.accuracy = new Calculator(res.accuracy)
            result.value.constitution = new Calculator(res.constitution)
            result.value.HP = new Calculator(res.HP)
            result.value.sun = new Calculator(res.sun)
            result.value.moon = new Calculator(res.moon)
            result.value.star = new Calculator(res.star)

            let suit315 = 0
            if (currentSuitLevel.value) {
                for (const [_key, value] of Object.entries(currentSuitLevel?.value)) {
                    if (value.level === 315) {
                        suit315++
                    }
                }
            }
            suitNumber315.value = suit315
            //套装属性
            if (suitNumber315.value >= 2) {
                result.value.coreAttribute.add(180)
            }
            if (suitNumber315.value >= 4) {
                //计算套装属性分配给四维中的哪个
                let maxValue = Math.max(res.criticalStrike, res.recovery, res.expertise, res.armorPenetration)
                switch (maxValue) {
                    case res.criticalStrike:
                        result.value.criticalStrike.add(195)
                        break;
                    case res.recovery:
                        result.value.recovery.add(195)
                        break;
                    case res.expertise:
                        result.value.expertise.add(195)
                        break;
                    case res.armorPenetration:
                        result.value.armorPenetration.add(195)
                        break;
                    default:
                        break;
                }
            }
            //判断护符是否佩戴了【稀世·度天地】
            if (currentEquipment.value[6] != null && currentEquipment.value[6] !== undefined && currentEquipment.value[6].id === 239
                || currentEquipment.value[7] != null && currentEquipment.value[7] !== undefined && currentEquipment.value[7].id === 239) {
                result.value.coreAttribute.add(result.value.coreAttribute * 0.01)
                result.value.criticalStrike.add(39)
                result.value.recovery.add(39)
                result.value.expertise.add(39)
                result.value.armorPenetration.add(39)
                result.value.HP.add(res.HP * 0.01)
            }

            //判断法印是否佩戴【太初玄元】
            if (currentEquipment.value[8] != null && currentEquipment.value[8] !== undefined && currentEquipment.value[8].equipmentName?.includes("太初玄元")) {
                if (result.value.accuracy.valueOf() > 585) {
                    result.value.accuracy.sub(78)
                    taiChuXunYuan.value = 0.05
                } else {
                    taiChuXunYuan.value = 0.01
                    result.value.accuracy.add(78)
                }
            } else {
                taiChuXunYuan.value = 0
            }
            maxValue.value = Math.max(result.value.criticalStrike.valueOf(), result.value.recovery.valueOf(), result.value.expertise.valueOf(), result.value.armorPenetration.valueOf())
            minValue.value = Math.min(result.value.criticalStrike.valueOf(), result.value.recovery.valueOf(), result.value.expertise.valueOf(), result.value.armorPenetration.valueOf())
            //判断令牌是否佩戴【稀世·渡彼岸】
            if (currentEquipment.value[9] != null && currentEquipment.value[9] !== undefined && currentEquipment.value[9].equipmentName?.includes("稀世·渡彼岸")) {
                //计算渡彼岸属性分配给哪个
                switch (maxValue.value) {
                    case result.value.criticalStrike.valueOf:
                        result.value.criticalStrike.add(190)
                        break;
                    case result.value.recovery.valueOf():
                        result.value.recovery.add(190)
                        break;
                    case result.value.expertise.valueOf():
                        result.value.expertise.add(190)
                        break;
                    case result.value.armorPenetration.valueOf():
                        result.value.armorPenetration.add(190)
                        break;
                    default:
                        break;
                }
            } else if (currentEquipment.value[9] != null && currentEquipment.value[9] !== undefined && currentEquipment.value[9].equipmentName?.includes("乾坤无极")) {
                //判断是否佩戴【乾坤无极】
                switch (minValue.value) {
                    case result.value.criticalStrike.valueOf():
                        result.value.criticalStrike.sub(78)
                        break;
                    case result.value.recovery.valueOf():
                        result.value.recovery.sub(78)
                        break;
                    case result.value.expertise.valueOf():
                        result.value.expertise.sub(78)
                        break;
                    case result.value.armorPenetration.valueOf():
                        result.value.armorPenetration.sub(78)
                        break;
                    default:
                        break;
                }
            }

            let type1 = -1
            let type2 = -1
            if (currentEquipment.value[6].equipmentName?.includes("旭日凌空") || currentEquipmentSunMoonStar.value[6]?.type === 0) {
                type1 = 0
            } else if (currentEquipment.value[6].equipmentName?.includes("孤月葬魂") || currentEquipmentSunMoonStar.value[6]?.type === 1) {
                type1 = 1
            } else if (currentEquipment.value[6].equipmentName?.includes("星陨离歌") || currentEquipmentSunMoonStar.value[6]?.type === 2) {
                type1 = 2
            } else if (currentEquipment.value[6].equipmentName?.includes("永夜哀歌") || currentEquipmentSunMoonStar.value[6]?.type === 3) {
                type1 = 3
            } else if (currentEquipment.value[6].equipmentName?.includes("混沌归墟") || currentEquipmentSunMoonStar.value[6]?.type === 4) {
                type1 = 4
            } else if (currentEquipment.value[6].equipmentName?.includes("太虚流光") || currentEquipmentSunMoonStar.value[6]?.type === 5) {
                type1 = 5
            }
            if (currentEquipment.value[7].equipmentName?.includes("旭日凌空") || currentEquipmentSunMoonStar.value[7]?.type === 0) {
                type2 = 0
            } else if (currentEquipment.value[7].equipmentName?.includes("孤月葬魂") || currentEquipmentSunMoonStar.value[7]?.type === 1) {
                type2 = 1
            } else if (currentEquipment.value[7].equipmentName?.includes("星陨离歌") || currentEquipmentSunMoonStar.value[7]?.type === 2) {
                type2 = 2
            } else if (currentEquipment.value[7].equipmentName?.includes("永夜哀歌") || currentEquipmentSunMoonStar.value[7]?.type === 3) {
                type2 = 3
            } else if (currentEquipment.value[7].equipmentName?.includes("混沌归墟") || currentEquipmentSunMoonStar.value[7]?.type === 4) {
                type2 = 4
            } else if (currentEquipment.value[7].equipmentName?.includes("太虚流光") || currentEquipmentSunMoonStar.value[7]?.type === 5) {
                type2 = 5
            }
            //     {name: "旭日凌空", type: 0, effect: "每带有2点耀日，造成的伤害和治疗增加0.55%"},
            //     {name: "孤月葬魂", type: 1, effect: "每带有2点残月，造成的属性伤害增加0.6%"},
            //     {name: "星陨离歌", type: 2, effect: "每带有2点流星，受到伤害降低0.5%，造成治疗增加0.55%"},
            //     {name: "永夜哀歌", type: 3, effect: "当同时带有曜日、残月和流星属性时，造成的会心伤害和会心治疗增加9%"},
            //     {name: "混沌归墟", type: 4, effect: "当带有的耀日、残月和流星属性中最高值大于17时，增加480点核心属性"},
            //     {name: "太虚流光", type: 5, effect: "每带有200点最高的额外属性（会心、专精、调息和破甲），增加耀日、残月和流星中最高值2.4倍的核心属性"},
            let sun = 0
            let moon = 0
            let star = 0
            for (let i in currentSunMoonStarValue.value) {
                switch (currentEquipment.value[i].galaxyType) {
                    case 1:
                        sun += currentSunMoonStarValue.value[i]
                        break
                    case 2:
                        moon += currentSunMoonStarValue.value[i]
                        break
                    case 3:
                        star += currentSunMoonStarValue.value[i]
                        break
                    default:
                        break
                }
            }
            result.value.sun.add(sun)
            result.value.moon.add(moon)
            result.value.star.add(star)
            let max = Math.max(sun, moon, star)
            sunHarm.value = 0
            moonHarm.value = 0
            starHarm1.value = 0
            starHarm2.value = 0
            sunMoonStarResult.value = []
            taiXuLiuGuang.value = 0
            switch (type1) {
                case 0://每带有2点耀日，造成的伤害和治疗增加0.55%
                    sunHarm.value = Math.trunc(sun / 2) * 0.55
                    sunMoonStarResult.value.push("【旭日凌空】" + sun + "耀日：" + sunHarm.value.toFixed(2) + "%伤害和治疗")
                    break
                case 1://每带有2点残月，造成的属性伤害增加0.6%
                    moonHarm.value = Math.trunc(moon / 2) * 0.6
                    sunMoonStarResult.value.push("【孤月葬魂】" + moon + "残月：" + moonHarm.value.toFixed(2) + "%属性伤害")
                    break
                case 2://每带有2点流星，受到伤害降低0.5%，造成治疗增加0.55%
                    starHarm1.value = Math.trunc(star / 2) * 0.5
                    starHarm2.value = Math.trunc(star / 2) * 0.55
                    sunMoonStarResult.value.push("【星陨离歌】" + star + "流星：" + starHarm1.value.toFixed(2) + "%伤害降低，" + starHarm2.value.toFixed(2) + "%治疗增加")
                    break
                case 3://当同时带有曜日、残月和流星属性时，造成的会心伤害和会心治疗增加9%
                    if (sun > 0 && moon > 0 && star > 0) {
                        sunMoonStarResult.value.push("【永夜哀歌】会心伤害和会心治疗增加9%")
                    }
                    break
                case 4://当带有的耀日、残月和流星属性中最高值大于17时，增加480点核心属性。
                    if (max > 17) {
                        result.value.coreAttribute.add(480);
                        sunMoonStarResult.value.push("【混沌归墟】核心属性增加：480")
                    }
                    break
                case 5://每带有200点最高的额外属性（会心、专精、调息和破甲），增加耀日、残月和流星中最高值2.4倍的核心属性
                    //计算最高属性/200的商
                    let maxV = Math.max(result.value.criticalStrike.valueOf(), result.value.recovery.valueOf(), result.value.expertise.valueOf(), result.value.armorPenetration.valueOf())
                    const quotient = Math.trunc(maxV / 200)
                    //获取日月星中的最大值，并*2.4
                    const maxN = max * 2.4
                    taiXuLiuGuang.value = quotient * maxN
                    result.value.coreAttribute.add(taiXuLiuGuang.value);
                    sunMoonStarResult.value.push("【太虚流光】核心属性增加：" + taiXuLiuGuang.value.toFixed(0))
                    break
                default:
                    break
            }
            switch (type2) {
                case 0://每带有2点耀日，造成的伤害和治疗增加0.55%
                    sunHarm.value = Math.trunc(sun / 2) * 0.55
                    sunMoonStarResult.value.push("【旭日凌空】" + sun + "耀日：" + sunHarm.value.toFixed(2) + "%伤害和治疗")
                    break
                case 1://每带有2点残月，造成的属性伤害增加0.6%
                    moonHarm.value = Math.trunc(moon / 2) * 0.6
                    sunMoonStarResult.value.push("【孤月葬魂】" + moon + "残月：" + moonHarm.value.toFixed(2) + "%属性伤害")
                    break
                case 2://每带有2点流星，受到伤害降低0.5%，造成治疗增加0.55%
                    starHarm1.value = Math.trunc(star / 2) * 0.5
                    starHarm2.value = Math.trunc(star / 2) * 0.55
                    sunMoonStarResult.value.push("【星陨离歌】" + star + "流星：" + starHarm1.value.toFixed(2) + "%伤害降低，" + starHarm2.value.toFixed(2) + "%治疗增加")
                    break
                case 3://当同时带有曜日、残月和流星属性时，造成的会心伤害和会心治疗增加9%
                    if (sun > 0 && moon > 0 && star > 0) {
                        sunMoonStarResult.value.push("【永夜哀歌】会心伤害和会心治疗增加9%")
                    }
                    break
                case 4://当带有的耀日、残月和流星属性中最高值大于17时，增加480点核心属性。
                    if (max > 17) {
                        result.value.coreAttribute.add(480);
                        sunMoonStarResult.value.push("【混沌归墟】核心属性增加：480")
                    }
                    break
                case 5://每带有200点最高的额外属性（会心、专精、调息和破甲），增加耀日、残月和流星中最高值2.4倍的核心属性
                    //计算最高属性/200的商
                    let maxV = Math.max(result.value.criticalStrike.valueOf(), result.value.recovery.valueOf(), result.value.expertise.valueOf(), result.value.armorPenetration.valueOf())
                    const quotient = Math.trunc(maxV / 200)
                    //获取日月星中的最大值，并*2.4
                    const maxN = max * 2.4
                    taiXuLiuGuang.value = quotient * maxN
                    result.value.coreAttribute.add(taiXuLiuGuang.value);
                    sunMoonStarResult.value.push("【太虚流光】核心属性增加：" + taiXuLiuGuang.value.toFixed(0))
                    break
                default:
                    break
            }
            let ssbx = result.value.coreAttribute.valueOf() * 0.2
            result.value.coreAttribute.add(lingYao.value ? 575 : 0).add(shengShengBuXi.value ? ssbx : 0)
            console.log('太虚流光:' + taiXuLiuGuang.value)

            if (currentEquipment.value[0].equipmentName?.includes("神兵") && currentEquipment.value[0].qualityLevel >= 335) {
                switch (currentClassName.value) {
                    case '青云':
                        currentEquipment.value[0].specialAttribute = "玩家增伤20%。雷：神剑御雷真诀附加玄冰之力，造成额外" + (50 + (6 * currentWeaponEnhancedLevel.value)) + "%的伤害。剑：道剑纵横附加玄冰之力，每段攻击造成额外的" + ((result.value.coreAttribute.valueOf() / 5) * (0.618 + 0.0773 * currentWeaponEnhancedLevel.value)).toFixed(0) + "法术伤害。"
                        break
                    case '鬼王':
                        currentEquipment.value[0].specialAttribute = "玩家增伤20%。煞：鬼斩夺命释放3次后，下一次聚灵斩·煞附加玄冰之力，造成额外" + (50 + (7.5 * currentWeaponEnhancedLevel.value)) + "%的伤害。罡：痴情咒减伤效果增加" + (4 + (0.6 * currentWeaponEnhancedLevel.value)) + "%；受到致命伤害时，获得冰封效果，免疫伤害并持续恢复最大气血30%的气血（冷却时间" + (8 - (0.3 * currentWeaponEnhancedLevel.value)) + "分钟）。"
                        break
                    case '焚香':
                        currentEquipment.value[0].specialAttribute = "玩家增伤20%。炎：每释放三次轰炎，下一次轰炎就会附加玄冰之力，造成额外" + (30 + (3 * currentWeaponEnhancedLevel.value)) + "%伤害。咒：万炎归宗附加玄冰之力，万炎归宗期间造成的伤害提高" + (50 + (5 * currentWeaponEnhancedLevel.value)) + "%的伤害"
                        break
                    case '合欢':
                        currentEquipment.value[0].specialAttribute = "玩家增伤20%。月每释放5次月刃之息，下一次风花雪月附加玄冰之力，每次会造成额外的" + ((result.value.coreAttribute.valueOf() / 5) * (0.535 + 0.067 * currentWeaponEnhancedLevel.value)).toFixed(0) + "物理伤害。影：每释放3次拂袖千星，下一次拂袖千星、拂袖千星·影附加玄冰之力，造成额外" + (50 + (6.2 * currentWeaponEnhancedLevel.value)) + "%的伤害。"
                        break
                    case '灵汐':
                        currentEquipment.value[0].specialAttribute = "玩家增伤20%。灵：每释放2次灵豚咏，下一次灵豚咏会附加玄冰之力，造成额外" + (40 + (5 * currentWeaponEnhancedLevel.value)) + "%的伤害。汐：释放上善之水立刻恢复周围所有队友" + ((result.value.coreAttribute.valueOf() / 5) * (1.339 + 0.1675 * currentWeaponEnhancedLevel.value)).toFixed(0) + "气血，每道水流造成气血恢复效果时，使自身法术攻击提高1%，持续60秒。"
                        break
                }
            }
            let specialAttribute = []
            currentEquipment.value.forEach((item, index) => {
                if (item != null) {
                    //把特殊效果放入集合里
                    if (item.specialAttribute?.length > 1) {
                        specialAttribute[index] = {type: item.equipmentSlot, content: item.specialAttribute, isRandom: item.isRandom}
                    }
                    if (currentEquipmentSunMoonStar.value[index] != null && currentEquipmentSunMoonStar.value[index].type >= 0) {
                        specialAttribute[index] = {
                            type: item.equipmentSlot,
                            content: '【赋能：' + currentEquipmentSunMoonStar.value[index].name + '】' + currentEquipmentSunMoonStar.value[index].effect
                        }
                    }
                }
            })
            specialAttributeList.value = specialAttribute

            let suitO = 0
            if (currentEquipment.value[6]?.equipmentName?.includes("幽海通玄") || currentEquipment.value[7]?.equipmentName?.includes("幽海通玄")) {
                suitO++
            }
            if (currentEquipment.value[0]?.equipmentName?.includes("九幽锋寒") || (currentEquipment.value[0]?.equipmentName?.includes("神兵") && currentEquipment.value[0]?.qualityLevel >= 335)) {
                suitO++
            }
            weaponSuit.value = suitO
        }
        const attributeCalculate = () => {
            resultHarm.value.gongji = (result.value.coreAttribute.valueOf() / 5)
            resultHarm.value.tiaoxi = result.value.recovery.valueOf()
            resultHarm.value.zhuanjing = result.value.expertise.valueOf()
            resultHarm.value.pojia = result.value.armorPenetration.valueOf()
            resultHarm1.value.gongji = 0
            resultHarm1.value.tiaoxi = 0
            resultHarm1.value.zhuanjing = 0
            resultHarm1.value.pojia = 0
            shanghai1(0, 0, 0, 0)
            attributeDialog.value = true
            shanghai()
        }
        const attributeDialog = ref(false)
        const attributeHarm = ref()
        const attributeHarm1 = ref()
        const resultHarm = ref({
            gongji: 0, tiaoxi: 0, zhuanjing: 0, pojia: 0, pojia1: 0,
        })
        const resultHarm1 = ref({
            gongji: 0, tiaoxi: 0, zhuanjing: 0, pojia: 0, pojia1: 0,
        })
        const pojia = (p, poJia) => {
            let po = (Number(p) + Number(poJia)) / 39
            if (po <= 40) {
                return po * 1.3
            } else if (po > 40 && po <= 50) {
                return 40 * 1.3 + (po - 40) * 1.04
            } else if (po > 50 && po <= 60) {
                return po * 1.3 - 0.2 * (po - 40) * 1.3 - 0.1 * (po - 48.75) * 1.3
            } else if (po > 60 && po <= 70) {
                return 40 * 1.3 + 10 * 1.04 + 10 * 0.91 + (po - 60) * 0.78
            } else if (po > 70 && po <= 80) {
                return 40 * 1.3 + 10 * 1.04 + 10 * 0.91 + 10 * 0.78 + (po - 70) * 0.65
            } else {
                if (po >= 100) {
                    po = 100
                }
                return -0.00511 * (po * po) + 1.499 * po
                // return po * (1.3 - 0.006 * po)
            }
        }
        const shanghai = () => {
            //手动修正伤害，目前发现计算公式和实际有刚好10%的缺口
            let xiuzheng = 0.9
            let sunS = sunHarm.value / 100
            let maxV = Math.max(result.value.criticalStrike.valueOf(), result.value.recovery.valueOf(), result.value.expertise.valueOf(), result.value.armorPenetration.valueOf())
            let minV = Math.min(result.value.criticalStrike.valueOf(), result.value.recovery.valueOf(), result.value.expertise.valueOf(), result.value.armorPenetration.valueOf())
            //幽海通玄增伤
            let youHai = (weaponSuit.value === 2 ? (Number(Math.trunc((maxV - minV) / 100)) / 1000) : 0)
            let f = 0.5
            //境界增伤
            let j = 0.155
            //剑拂云增伤
            let jfyHarm = 0.2
            let gongji = (resultHarm.value.gongji * 1.03).toFixed(0)
            let faShuGongJi = resultHarm.value.gongji.toFixed(0)
            let tiaoxi = (resultHarm.value.tiaoxi / 39).toFixed(2) / 100
            let y = pojia(resultHarm.value.pojia, 0)
            let poJia = Number((0.5 + (y / 100) * f).toFixed(3))
            resultHarm.value.pojia1 = poJia
            console.log("无视防御结果=" + y.toFixed(2) + "%", "破甲转化率=" + poJia)
            let taoZhuang = (suitSize2.value >= 2 ? 0.2 : 0)
            let taoZhuang1 = (suitSize2.value >= 4 ? 0.5 : 0)
            // let taozhuang = 1
            //专精伤害加成百分比 青霜、穿星、剑扫
            let zhuanjingShanghai = (resultHarm.value.zhuanjing / 30) / 100 + 1

            //穿星
            let chuanxing0 = gongji * 0.2774 * (1 + 0.15 + taoZhuang + youHai + j) * zhuanjingShanghai * poJia * xiuzheng
            let chuanxing = chuanxing0 * 5
            let chuanxing1 = chuanxing * (1 + sunS + taiChuXunYuan.value)
            let chuanxing2 = chuanxing * (1 + 0.2 + tiaoxi) * (1 + sunS + taiChuXunYuan.value)
            let cx = (chuanxing1 + chuanxing2)
            //青霜
            let qingshuang = gongji * 0.8222 * (1 + 0.15 + j + youHai) * 1.25 * zhuanjingShanghai * poJia * (1 + sunS + taiChuXunYuan.value) * xiuzheng

            let daojianC = (jfy) => {
                return (1 + taoZhuang1 + jfy + taoZhuang + j + youHai) * 1.2 * poJia * (1 + sunS + taiChuXunYuan.value)
            }
            //道剑 0.5为剑心通明，无双40%为独立乘区
            let daojian1 = (jfy) => {
                // return gongji * 0.667 * daojianC(jfy)
                return gongji * 0.6897 * daojianC(jfy)
            }
            let daojian7 = (jfy) => {
                // return gongji * 1.44 * daojianC(jfy)
                return gongji * 1.455 * daojianC(jfy)
            }
            let daojian = (jfy) => {
                return daojian1(jfy) * 6 + daojian7(jfy)
            }
            //贯虹
            // let guanhong = gongji * 0.8 * (1 + j + youHai) * poJia * (1 + sunS + taiChuXunYuan.value) * 0.875
            let guanhong = gongji * 0.8222 * (1 + j + youHai) * poJia * (1 + sunS + taiChuXunYuan.value) * 0.875

            //剑浮云 总系数=2.2614
            let jianFuYunC = (jfy) => {
                return (1 + j + youHai + jfy) * poJia * xiuzheng * (1 + sunS + taiChuXunYuan.value)
            }
            let jianFuYun1 = (jfy) => {
                return gongji * 0.3204 * jianFuYunC(jfy)
            }
            let jianFuYun2 = jianFuYun1(0.05)
            let jianFuYun3 = jianFuYun1(0.1)
            let jianFuYun4 = gongji * 1.3 * jianFuYunC(0.15)

            let jfyTotal = jianFuYun1(0) + jianFuYun2 + jianFuYun3 + jianFuYun4

            //长歌
            let changge = faShuGongJi * (0.618 + 0.0773 * currentWeaponEnhancedLevel.value) * poJia * (1 + (sunS / 100))
            //怒剑劫
            let nujianjie = (faShuGongJi * 4) * (1 + 0.25 + youHai + j) * poJia * (1 + sunS + taiChuXunYuan.value) * 0.93
            //剑意留痕
            let jianyiliuhen = chuanxing2 * 0.3 * 1.5 * 1.25

            console.log("-----------攻击力" + gongji + "--破甲系数" + poJia.toFixed(3) + "--专精加成" + zhuanjingShanghai + "--幽海通玄" + (1 + youHai) + "---------")
            console.log("穿星", cx.toFixed(0), "第一段伤害：" + chuanxing0, "前五段总合：" + chuanxing)
            console.log("穿星尾刀", (chuanxing2).toFixed(0))
            console.log("青霜", qingshuang.toFixed(0))
            console.log("道剑", daojian(0).toFixed(0), "道剑纵横一段：" + daojian1(0), "道剑纵横尾刀：" + daojian7(0))
            console.log("剑拂云道剑", daojian(0.2).toFixed(0), "道剑纵横一段：" + daojian1(0.2), "道剑纵横尾刀：" + daojian7(0.2))
            console.log("贯虹", guanhong.toFixed(0))
            console.log("剑拂云", jfyTotal.toFixed(0), jianFuYun1(0), jianFuYun2, jianFuYun3, jianFuYun4)
            console.log("长歌", changge.toFixed(0), (changge * 7).toFixed(0))
            console.log("怒剑劫", nujianjie.toFixed(0),)
            console.log("剑意留痕", jianyiliuhen.toFixed(0))
            console.log("---------------------------------模拟一分钟-----------------------------------------")
            let a = cx * (1 + 0.5 + 0.2)
            let b = qingshuang * (1 + 0.5 + 0.2)
            let c = daojian(jfyHarm) * 1.4
            let d = guanhong * (1 + 0.5 + 0.2)
            let e = jianyiliuhen
            console.log("剑心穿星=" + a.toFixed(0), "剑心穿星*4=" + (a * 4).toFixed(0), "剑拂云穿星*2=" + (cx * 1.2 * 2).toFixed(0))
            console.log("剑心青霜=" + b.toFixed(0), "剑心青霜*3=" + (b * 3).toFixed(0), "剑拂云青霜*9=" + qingshuang * 1.2 * 9, "普通青霜*2=" + qingshuang * 2)
            console.log("4层无双道剑=" + c.toFixed(0), "4层无双道剑*2=" + (c * 2).toFixed(0))
            console.log("剑心贯虹=" + d.toFixed(0), "剑心贯虹*7=" + (d * 7).toFixed(0), "剑拂云贯虹*17=" + (guanhong * 1.2 * 17).toFixed(0), "普通贯虹*7=" + (guanhong * 7).toFixed(0))
            console.log("剑心剑拂云=" + (jfyTotal * 1.5).toFixed(0), "平缓剑拂云=" + jfyTotal * 3)
            console.log("长歌=" + changge * 7, "一分钟两次=" + (changge * 7) * 2)
            console.log("剑心怒剑劫=" + (nujianjie * (1 + 0.5 + 0.2)), "平缓怒剑劫=" + nujianjie * 1.2)
            console.log("剑意留痕=" + e.toFixed(0), "剑心尾刀剑意留痕*4=" + (e * (1 + 0.5 + 0.2) * 4).toFixed(0), "剑浮云尾刀剑意留痕*2=" + (e * 1.2 * 2).toFixed(0))

            let total = (a * 4) + (cx * 1.2 * 2) + (b * 3) + (qingshuang * 1.2 * 9) + (qingshuang * 2) + (c * 2) + (d * 7) + (guanhong * 1.2 * 17) +
                (guanhong * 7) + (jfyTotal * 1.5) + (jfyTotal * 3) + (changge * 7 * 2) + (nujianjie * 1.5 * 1.2) + (nujianjie * 1.2) + (e * (1 + 0.5 + 0.2) * 4) + (e * 1.2 * 2)
            console.log("总伤害=" + total.toFixed(2))
            attributeHarm.value = {
                youHai: youHai,
                chuanxing: cx,
                chuanxingEnd: chuanxing2,
                qingshuang: qingshuang,
                daojian: daojian(0),
                guanhong: guanhong,
                jianfuyun: jfyTotal,
                jianfuyun1: jianFuYun1(0),
                jianfuyun2: jianFuYun2,
                jianfuyun3: jianFuYun3,
                jianfuyun4: jianFuYun4,
                changge: changge,
                nujianjie: nujianjie,
                jianyiliuhen: jianyiliuhen,
                a: a,
                b: b,
                c: c,
                d: d,
                e: e,
                total: total.toFixed(0)
            }
        }
        const shanghai1 = (gj, tx, zj, pj) => {
            console.log(gj, tx, zj, pj)

            let t = resultHarm.value.tiaoxi + Number(tx)
            let z = resultHarm.value.zhuanjing + Number(zj)
            let p = resultHarm.value.pojia + Number(pj)

            let maxV = Math.max(result.value.criticalStrike.valueOf(), t, z, p)
            let minV = Math.min(result.value.criticalStrike.valueOf(), t, z, p)

            let txlg = 0
            let max = Math.max(result.value.sun.valueOf(), result.value.moon.valueOf(), result.value.star.valueOf())
            const quotient = Math.trunc(maxV / 200)
            if (currentEquipment.value[6].equipmentName?.includes("太虚流光") || currentEquipmentSunMoonStar.value[6]?.type === 5) {
                //获取日月星中的最大值，并*2.4
                const maxN = max * 2.4
                txlg = quotient * maxN
            } else if (currentEquipment.value[7].equipmentName?.includes("太虚流光") || currentEquipmentSunMoonStar.value[7]?.type === 5) {
                //获取日月星中的最大值，并*2.4
                const maxN = max * 2.4
                txlg = quotient * maxN
            }
            let core = (result.value.coreAttribute.valueOf() - taiXuLiuGuang.value) + txlg
            resultHarm.value.gongji = core / 5
            let g = ((resultHarm.value.gongji + Number(gj)) * 1.03).toFixed(0)
            let gg = (resultHarm.value.gongji + Number(gj)).toFixed(0)
            let xiuzheng = 0.9
            let sunS = sunHarm.value / 100
            //幽海通玄增伤
            let youHai = (weaponSuit.value === 2 ? (Number(Math.trunc((maxV - minV) / 100)) / 1000) : 0)
            console.log("最大值五维：" + maxV, "幽海通玄：" + youHai)
            let f = 0.5
            //境界增伤
            let j = 0.155
            //剑拂云增伤
            let jfyHarm = 0.2
            let gongji = Number(g)
            let faShuGongJi = Number(gg)
            let tiaoxi = (t / 39).toFixed(2) / 100
            let y = pojia(p, 0)
            let poJia = Number((0.5 + (y / 100) * f).toFixed(3))
            let taoZhuang = (suitSize2.value >= 4 ? 0.2 : 0)
            let taoZhuang1 = (suitSize2.value >= 4 ? 0.5 : 0)
            //专精伤害加成百分比 青霜、穿星、剑扫
            let zhuanjingShanghai = (z / 30) / 100 + 1

            //穿星
            let chuanxing0 = gongji * 0.2774 * (1 + 0.15 + taoZhuang + youHai + j) * zhuanjingShanghai * poJia * xiuzheng
            let chuanxing = chuanxing0 * 5
            let chuanxing1 = chuanxing * (1 + sunS + taiChuXunYuan.value)
            let chuanxing2 = chuanxing * (1 + 0.2 + tiaoxi) * (1 + sunS + taiChuXunYuan.value)
            let cx = (chuanxing1 + chuanxing2)
            //青霜
            let qingshuang = gongji * 0.8222 * (1 + 0.15 + j + youHai) * 1.25 * zhuanjingShanghai * poJia * (1 + sunS + taiChuXunYuan.value) * xiuzheng

            let daojianC = (jfy) => {
                return (1 + taoZhuang1 + jfy + taoZhuang + j + youHai) * 1.2 * poJia * (1 + sunS + taiChuXunYuan.value)
            }
            //道剑 0.5为剑心通明，无双40%为独立乘区
            let daojian1 = (jfy) => {
                // return gongji * 0.667 * daojianC(jfy)
                return gongji * 0.6897 * daojianC(jfy)
            }
            let daojian7 = (jfy) => {
                // return gongji * 1.44 * daojianC(jfy)
                return gongji * 1.455 * daojianC(jfy)
            }
            let daojian = (jfy) => {
                return daojian1(jfy) * 6 + daojian7(jfy)
            }
            //贯虹
            // let guanhong = gongji * 0.8 * (1 + j + youHai) * poJia * (1 + sunS + taiChuXunYuan.value) * 0.875
            let guanhong = gongji * 0.8222 * (1 + j + youHai) * poJia * (1 + sunS + taiChuXunYuan.value) * 0.875

            //剑浮云 总系数=2.2614
            let jianFuYunC = (jfy) => {
                return (1 + j + youHai + jfy) * poJia * xiuzheng * (1 + sunS + taiChuXunYuan.value)
            }
            let jianFuYun1 = (jfy) => {
                return gongji * 0.3204 * jianFuYunC(jfy)
            }
            let jianFuYun2 = jianFuYun1(0.05)
            let jianFuYun3 = jianFuYun1(0.1)
            let jianFuYun4 = gongji * 1.3 * jianFuYunC(0.15)

            let jfyTotal = jianFuYun1(0) + jianFuYun2 + jianFuYun3 + jianFuYun4

            //长歌
            let changge = faShuGongJi * (0.618 + 0.0773 * currentWeaponEnhancedLevel.value) * poJia * (1 + (sunS / 100))
            //怒剑劫
            let nujianjie = (faShuGongJi * 4) * (1 + 0.25 + youHai + j) * poJia * (1 + sunS + taiChuXunYuan.value) * 0.93
            //剑意留痕
            let jianyiliuhen = chuanxing2 * 0.3 * 1.5 * 1.25
            let a = cx * (1 + 0.5 + 0.2)
            let b = qingshuang * (1 + 0.5 + 0.2)
            let c = daojian(jfyHarm) * 1.4
            let d = guanhong * (1 + 0.5 + 0.2)
            let e = jianyiliuhen

            let total = (a * 4) + (cx * 1.2 * 2) + (b * 3) + (qingshuang * 1.2 * 9) + (qingshuang * 2) + (c * 2) + (d * 7) + (guanhong * 1.2 * 17) +
                (guanhong * 7) + (jfyTotal * 1.5) + (jfyTotal * 3) + (changge * 7 * 2) + (nujianjie * 1.5 * 1.2) + (nujianjie * 1.2) + (e * (1 + 0.5 + 0.2) * 4) + (e * 1.2 * 2)
            console.log("总伤害=" + total.toFixed(0))
            attributeHarm1.value = {
                youHai: youHai,
                chuanxing: cx,
                chuanxingEnd: chuanxing2,
                qingshuang: qingshuang,
                daojian: daojian(0),
                guanhong: guanhong,
                jianfuyun: jfyTotal,
                jianfuyun1: jianFuYun1(0),
                jianfuyun2: jianFuYun2,
                jianfuyun3: jianFuYun3,
                jianfuyun4: jianFuYun4,
                changge: changge,
                nujianjie: nujianjie,
                jianyiliuhen: jianyiliuhen,
                a: a,
                b: b,
                c: c,
                d: d,
                e: e,
                total: total.toFixed(0)
            }
        }

        //保存配装
        const save = () => {
            currentDanYao.value = danYaoList[0]
            currentShiPin.value = shiPinList[0]
            lingYao.value = false
            shengShengBuXi.value = false
            danYaoSelectChange(currentDanYao.value)
            shiPinSelectChange(currentShiPin.value)
            lingYaoSelectChange(lingYao.value)
            shengShengSelectChange(shengShengBuXi.value)
            if (user.id === 0) {
                this.$emitter.emit("login", true)
                // this.$emitter.off("login")
                return false
            }
            let count = currentEquipment.value.filter(equipment => equipment.id > 0).length
            let indexM = -1
            let random = currentEquipment.value.find((item, index) => {
                indexM = index
                return item.isRandom === 1
            })
            if (random !== undefined && randomAttribute1.value[indexM].type === undefined) {
                ElMessage.error("你还未选择【" + random.equipmentName + "】装备的属性")
                return
            }
            if (random !== undefined && randomAttribute2.value[indexM].type === undefined) {
                ElMessage.error("你还未选择【" + random.equipmentName + "】装备的属性")
                return
            }
            if (count === 10) {
                submitEquipmentDialog.value = true
            } else if (count > 10) {
                ElMessage.error("装备列表异常，请刷新页面重新搭配")
            } else {
                ElMessage.error("请完善配装内容")
            }
            return false
        }
        //配装内容保存成图片
        const saveImage = () => {
            currentDanYao.value = danYaoList[0]
            currentShiPin.value = shiPinList[0]
            lingYao.value = false
            shengShengBuXi.value = false
            danYaoSelectChange(currentDanYao.value)
            shiPinSelectChange(currentShiPin.value)
            lingYaoSelectChange(lingYao.value)
            shengShengSelectChange(shengShengBuXi.value)
            let count = currentEquipment.value.filter(equipment => equipment.id > 0).length
            let indexM = -1
            let random = currentEquipment.value.find((item, index) => {
                indexM = index
                return item.isRandom === 1
            })
            if (random !== undefined && randomAttribute1.value[indexM]?.type === undefined) {
                ElMessage.error("你还未选择【" + random.equipmentName + "】装备的属性")
                return
            }
            if (random !== undefined && randomAttribute2.value[indexM].type === undefined) {
                ElMessage.error("你还未选择【" + random.equipmentName + "】装备的属性")
                return
            }
            if (count === 10) {
                ElMessageBox.prompt("请为你的配装起个名字", "分享配装",
                    {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        inputType: "text",
                    }
                ).then(({value}) => {
                    buildName.value = value
                    isShowSaveImageDialog.value = true
                    setTimeout(() => {
                        saveImage1()
                    }, 500)
                })
            } else if (count > 10) {
                ElMessage.error("装备列表异常，请刷新页面重新搭配")
            } else {
                ElMessage.error("请完善配装内容")
            }

        }

        const saveImage1 = async () => {
            const element = document.getElementById("imageSave") // 获取DOM元素引用
            const shareImage = document.getElementById("shareImage")
            html2canvas(element).then(canvas => {
                shareImage.innerHTML = ''
                shareImage.appendChild(canvas)
            });
        }

        //提交接口
        const submitEquipmentBtn = () => {
            let zhuangbeiList = []
            let suit = []
            currentEquipment.value.forEach((item, index) => {
                let inlayId = []
                switch (index) {
                    case 1:
                        let head = []
                        for (let i in currentInlay.value.head) {
                            head.push({id: currentInlay.value.head[i].id})
                        }
                        inlayId = head
                        break;
                    case 2:
                        let upperBody = []
                        for (let i in currentInlay.value.clothing) {
                            upperBody.push({id: currentInlay.value.clothing[i].id})
                        }
                        inlayId = upperBody
                        break
                    case 3:
                        let hand = []
                        for (let i in currentInlay.value.hand) {
                            hand.push({id: currentInlay.value.hand[i].id})
                        }
                        inlayId = hand
                        break
                    case 4:
                        let waist = []
                        for (let i in currentInlay.value.waist) {
                            waist.push({id: currentInlay.value.waist[i].id})
                        }
                        inlayId = waist
                        break;
                    default:
                        break;
                }
                zhuangbeiList.push({
                    type: index,
                    equipmentId: item.id,
                    inlayId: inlayId
                })
                if (item.partType > 0 && item.partType < 6) {
                    if (!item.equipmentSource.includes("套装") && item.classSpecialize === currentSuitLevel.value[item.partType]?.type) {
                        //如果当前的装备不是套装，并且他的类型是套装
                        //说明当前partType的装备被融合成了套装
                        suit.push({
                            level: currentSuitLevel.value[item.partType]?.level,
                            partType: item.partType,
                            type: currentSuitLevel.value[item.partType]?.type,
                            name: currentSuitLevel.value[item.partType]?.name
                        })
                    }
                }
            })
            submitEquipmentFrom.value.equipmentList = zhuangbeiList
            if (submitEquipmentFrom.value.name.length < 3) {
                ElMessage.error("请输入配装名称，名称长度大于2个字符")
                return
            }
            http.post('equipment/builds', {
                userId: user.id,
                buildClass: currentClassName.value,
                buildSchool: currentClassSchool.value,
                buildName: submitEquipmentFrom.value.name,
                equipmentBuilds: submitEquipmentFrom.value.equipmentList,
                amagicWeaponId: currentAMagicWeapon.value?.id || 0,//法宝
                skillTree: {//天书
                    criticalStrike: currentSkillTreeCriticalStrike.value,
                    recovery: currentSkillTreeRecovery.value,
                    expertise: currentSkillTreeExpertise.value,
                    defense: currentSkillTreeDefense.value,
                    hp: currentSkillTreeHP.value
                },
                talismanLevelAttribute: JSON.stringify(aMagicWeapon),//法宝等级属性
                starSpirit: JSON.stringify(currentXingPo.value),//星魄
                setFusion: suit.length === 0 ? null : JSON.stringify(suit),//融合套装
                charmSetFusion: JSON.stringify(currentEquipmentSunMoonStar.value),
                galaxyAttribute: JSON.stringify(currentSunMoonStarValue.value),
                randomValue: JSON.stringify({attribute1: randomAttribute1.value, attribute2: randomAttribute2.value})
            }).then(response => {
                if (response.data.code === 200) {
                    ElMessage.success("提交成功")
                    submitEquipmentDialog.value = false
                } else {
                    ElMessage.error(response.data.message)
                }
            }).catch(error => {
                if (error.status === 403) {
                    ElMessage.error("登录状态失效，请重新登录");
                } else {
                    ElMessage.error(error.message)
                }
            })
        }
        const submitEquipmentCancel = () => {
            submitEquipmentFrom.value.name = ""
            submitEquipmentFrom.value.school = ""
            submitEquipmentFrom.value.equipmentList = []
            submitEquipmentDialog.value = false
        }
        const hotConfigurationListClick = (id) => {
            getEquipmentBuild(id)
        }

        const getClassImage = (name) => {
            const types = {
                '青云': "url('/equipment-ico/qingyun_ico.png')",
                '焚香': "url('/equipment-ico/fenxiang_ico.png')",
                '鬼王': "url('/equipment-ico/guiwang_ico.png')",
                '合欢': "url('/equipment-ico/hehuan_ico.png')",
                '灵汐': "url('/equipment-ico/lingxi_ico.png')"
            }
            return types[name]
        }
        const getClassTagType = (buildClass) => {
            const types = {
                '青云': 'primary',  // 蓝色系 #409EFF
                '焚香': 'danger',  // 红色系 #F56C6C
                '鬼王': 'dark',  // 黑色系 #303133
                '合欢': 'purple',  // 紫色系 #8A2BE2
                '灵汐': 'success'  // 绿色系 #67C23A
            }
            return types[buildClass]
        }
        const getPartImage = (name) => {
            const types = {
                '武器': "url('/part-ico/武器.png')",
                '头部': "url('/part-ico/头部.png')",
                '上身': "url('/part-ico/上身.png')",
                '手部': "url('/part-ico/手部.png')",
                '腰部': "url('/part-ico/腰部.png')",
                '脚部': "url('/part-ico/脚部.png')",
                '护符': "url('/part-ico/护符.png')",
                '法印': "url('/part-ico/法印.png')",
                '令牌': "url('/part-ico/令牌.png')",
            }
            return types[name]
        }
        const getInlay1 = (name) => {
            const types = {
                '41核心': "url('/part-ico/41核心.png')",
                '49核心': "url('/part-ico/49核心.png')",
            }
            return types[name]

        }
        const getInlay2 = (name) => {
            const types = {
                '162气血': "url('/part-ico/162气血.png')",
                '195气血': "url('/part-ico/195气血.png')",
            }
            return types[name]
        }
        const getInlay3 = (name) => {
            const types = {
                '12专精': "url('/part-ico/12专精.png')",
                '14专精': "url('/part-ico/14专精.png')",
                '12会心': "url('/part-ico/12会心.png')",
                '14会心': "url('/part-ico/14会心.png')",
                '12命中': "url('/part-ico/12命中.png')",
                '14命中': "url('/part-ico/14命中.png')",
                '12破甲': "url('/part-ico/12破甲.png')",
                '14破甲': "url('/part-ico/14破甲.png')",
                '12调息': "url('/part-ico/12调息.png')",
                '14调息': "url('/part-ico/14调息.png')",
            }
            return types[name]
        }
        setDefData()
        getInlay()
        selectProfessionChange(currentClassName.value)
        getRealmLevel()
        getAMagicWeapon()

        onMounted(() => {
            emitter.on('applyConfig', (config) => {
                nextTick(() => {
                    setTimeout(() => {
                        // switch (config.buildClass) {
                        //     case "青云":
                        //         this.imagePath = "url('/bgimage/bg-qy.jpg')"
                        //         break
                        //     case "焚香":
                        //         this.imagePath = "url('/bgimage/bg-fx.jpg')"
                        //         break
                        //     case "鬼王":
                        //         this.imagePath = "url('/bgimage/bg-gw.jpg')"
                        //         break
                        //     case "合欢":
                        //         this.imagePath = "url('/bgimage/bg-hh.jpg')"
                        //         break
                        //     case "灵汐":
                        //         this.imagePath = "url('/bgimage/bg-lx.jpg')"
                        //         break
                        // }
                        getEquipmentBuild(config.id)
                    }, 500)
                })
            })
        })
        onBeforeRouteLeave((_to, _from, next) => {
            //next()必须调用，否则无法跳转
            emitter.off("applyConfig")
            next()
        })

        return {
            armorEnhancedChange,
            selectProfessionChange,
            equipmentLevelChange,
            equipmentSelectChange,
            equipmentSelectChange1,
            inlaySelectChange,
            suitChange,
            randomAttributeChange1,
            randomAttributeChange2,
            weaponEnhancedSelectChange,
            enhancedJewelryLevelList,
            armorEnhancedSelectChange,
            JewelryEnhancedSelectChange,
            aMagicWeaponSelectChange,
            xingPoSelectChange,
            sunMoonStarNumberChange,
            sunMoonStarChange,
            save,
            saveImage,
            submitEquipmentBtn,
            submitEquipmentCancel,
            getClassImage,
            getClassTagType,
            getPartImage,
            getInlay1,
            getInlay2,
            getInlay3,
            attributeDialog,
            user,
            className,
            realmList,
            currentClassName,
            currentClassSchool,
            currentRealm,
            aMagicWeapon,
            aMagicWeaponList,
            equipmentLevel,
            currentEquipment,
            classEquipment,
            currentWeaponEnhancedLevel,
            currentArmorEnhancedLevel,
            currentJewelryEnhancedLevel,
            enhancedLevel,
            weaponEnhancedSelectList,
            enhancedAttribute,
            currentInlay,
            suitLevel,
            currentSuitLevel,
            suitNumber315,
            suitSize1,
            suitSize2,
            suitAttribute1,
            suitAttribute2,
            weaponSuit,
            inlayList,
            currentSunMoonStarValue,
            sunMoonStar,
            currentEquipmentSunMoonStar,
            randomAttribute1,
            randomAttribute2,
            randomAttribute1List,
            randomAttribute2List,
            sunMoonStarResult,
            currentSkillTreeCriticalStrike,
            skillTreeCriticalStrike,
            currentSkillTreeRecovery,
            skillTreeRecovery,
            currentSkillTreeExpertise,
            skillTreeExpertise,
            currentSkillTreeDefense,
            skillTreeDefense,
            currentSkillTreeHP,
            skillTreeHp,
            isShowCriticalStrike,
            isShowRecovery,
            isShowExpertise,
            isShowDefense,
            isShowHp,
            currentAMagicWeapon,
            xingPoLevel,
            currentXingPo,
            result,
            classSchool,
            specialAttributeList,
            buildName,
            submitEquipmentFrom,
            isShowSaveImageDialog,
            submitEquipmentDialog,
            attributeHarm,
            attributeHarm1,
            sunHarm,
            resultHarm,
            resultHarm1,
            taiChuXunYuan,
            attributeCalculate,
            shanghai1,
            pojia,
            danYaoList,
            currentDanYao,
            danYaoSelectChange,
            shiPinList,
            currentShiPin,
            shiPinSelectChange,
            lingYao,
            lingYaoSelectChange,
            shengShengBuXi,
            shengShengSelectChange

        }
    },
}